Exemplo n.º 1
0
/**
 * Hook to run a cron job.
 *
 * @param array &$croninfo  Output
 */
function oauth_hook_cron(&$croninfo)
{
    assert('is_array($croninfo)');
    assert('array_key_exists("summary", $croninfo)');
    assert('array_key_exists("tag", $croninfo)');
    $oauthconfig = SimpleSAML_Configuration::getOptionalConfig('module_statistics.php');
    if (is_null($oauthconfig->getValue('cron_tag', 'hourly'))) {
        return;
    }
    if ($oauthconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) {
        return;
    }
    try {
        $store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
        $cleaned = $store->removeExpired();
        #		if ($cleaned > 0)
        $croninfo['summary'][] = 'OAuth clean up. Removed ' . $cleaned . ' expired entries from OAuth storage.';
    } catch (Exception $e) {
        $message = 'OAuth clean up cron script failed: ' . $e->getMessage();
        SimpleSAML_Logger::warning($message);
        $croninfo['summary'][] = $message;
    }
}
Exemplo n.º 2
0
<?php

/* Load simpleSAMLphp, configuration and metadata */
$config = SimpleSAML_Configuration::getInstance();
$session = SimpleSAML_Session::getSessionFromRequest();
$oauthconfig = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
$store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
$authsource = "admin";
// force admin to authenticate as registry maintainer
$useridattr = $oauthconfig->getValue('useridattr', 'user');
if ($session->isValid($authsource)) {
    $attributes = $session->getAuthData($authsource, 'Attributes');
    // Check if userid exists
    if (!isset($attributes[$useridattr])) {
        throw new Exception('User ID is missing');
    }
    $userid = $attributes[$useridattr][0];
} else {
    $as = SimpleSAML_Auth_Source::getById($authsource);
    $as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
}
function requireOwnership($entry, $userid)
{
    if (!isset($entry['owner'])) {
        throw new Exception('OAuth Consumer has no owner. Which means no one is granted access, not even you.');
    }
    if ($entry['owner'] !== $userid) {
        throw new Exception('OAuth Consumer has an owner that is not equal to your userid, hence you are not granted access.');
    }
}
if (isset($_REQUEST['delete'])) {
Exemplo n.º 3
0
<?php

/* Load simpleSAMLphp, configuration and metadata */
$config = SimpleSAML_Configuration::getInstance();
$session = SimpleSAML_Session::getSessionFromRequest();
$oauthconfig = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
$store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
//$authsource = $oauthconfig->getValue('auth', 'admin');
$authsource = "admin";
// force admin to authenticate as registry maintainer
$useridattr = $oauthconfig->getValue('useridattr', 'user');
//$useridattr = $oauthconfig->getValue('useridattr', 'uid');
if ($session->isValid($authsource)) {
    $attributes = $session->getAttributes();
    // Check if userid exists
    if (!isset($attributes[$useridattr])) {
        throw new Exception('User ID is missing');
    }
    $userid = $attributes[$useridattr][0];
} else {
    SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL());
}
function requireOwnership($entry, $userid)
{
    if (!isset($entry['owner'])) {
        throw new Exception('OAuth Consumer has no owner. Which means no one is granted access, not even you.');
    }
    if ($entry['owner'] !== $userid) {
        throw new Exception('OAuth Consumer has an owner that is not equal to your userid, hence you are not granted access.');
    }
}
Exemplo n.º 4
0
function push($file, $fileWithoutExt, $aid, $type)
{
    if (!file_exists($file)) {
        throw new Exception('Could not find file: ' . $file);
    }
    $fileContent = file_get_contents($file);
    global $baseDir;
    require_once $baseDir . '/modules/oauth/libextinc/OAuth.php';
    $translationconfig = SimpleSAML_Configuration::getConfig('translation.php');
    $baseurl = $translationconfig->getString('baseurl');
    $key = $translationconfig->getString('key');
    $secret = $translationconfig->getString('secret');
    echo 'Using OAuth to authenticate you to the translation portal' . "\n";
    $consumer = new sspmod_oauth_Consumer($key, $secret);
    $storage = new sspmod_core_Storage_SQLPermanentStorage('oauth_clientcache');
    $cachedAccessToken = $storage->get('accesstoken', 'translation', '');
    $accessToken = NULL;
    if (empty($cachedAccessToken)) {
        // Get the request token
        $requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/requestToken.php');
        echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n";
        // Authorize the request token
        $url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, FALSE);
        echo 'Go to this URL to authenticate/authorize the request: ' . $url . "\n";
        system('open ' . $url);
        ssp_readline('Click enter when you have completed the authorization step using your web browser...');
        // Replace the request token with an access token
        $accessToken = $consumer->getAccessToken($baseurl . '/module.php/oauth/accessToken.php', $requestToken);
        echo "Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]\n";
        $storage->set('accesstoken', 'translation', '', $accessToken);
    } else {
        $accessToken = $cachedAccessToken['value'];
        echo 'Successfully read OAuth Access Token from cache [' . $accessToken->key . ']' . "\n";
    }
    $pushURL = $baseurl . '/module.php/translationportal/push.php';
    $request = array('data' => base64_encode($fileContent), 'file' => $fileWithoutExt, 'aid' => $aid, 'type' => $type);
    $result = $consumer->postRequest($pushURL, $accessToken, $request);
    echo $result;
}