/** * Log-in using MySpace platform * * @param array &$state Information about the current authentication. */ public function authenticate(&$state) { assert('is_array($state)'); /* We are going to need the authId in order to retrieve this authentication source later. */ $state[self::AUTHID] = $this->authId; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); // Get the request token $requestToken = $consumer->getRequestToken('http://api.myspace.com/request_token'); SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); $state['authmyspace:requestToken'] = $requestToken; $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); SimpleSAML_Logger::debug('authmyspace auth state id = ' . $stateID); // Authorize the request token $consumer->getAuthorizeRequest('http://api.myspace.com/authorize', $requestToken, TRUE, SimpleSAML_Module::getModuleUrl('authmyspace') . '/linkback.php?stateid=' . $stateID); }
/** * Log-in using Twitter platform * * @param array &$state Information about the current authentication. */ public function authenticate(&$state) { assert('is_array($state)'); /* We are going to need the authId in order to retrieve this authentication source later. */ $state[self::AUTHID] = $this->authId; $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); // Get the request token $linkback = SimpleSAML_Module::getModuleURL('authtwitter/linkback.php', array('AuthState' => $stateID)); $requestToken = $consumer->getRequestToken('https://api.twitter.com/oauth/request_token', array('oauth_callback' => $linkback)); SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); $state['authtwitter:authdata:requestToken'] = $requestToken; SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); // Authorize the request token $consumer->getAuthorizeRequest('https://api.twitter.com/oauth/authenticate', $requestToken); }
/** * Log-in using LinkedIn platform * Documentation at: http://developer.linkedin.com/docs/DOC-1008 * * @param array &$state Information about the current authentication. */ public function authenticate(&$state) { assert('is_array($state)'); // We are going to need the authId in order to retrieve this authentication source later $state[self::AUTHID] = $this->authId; $stateID = SimpleSAML_Auth_State::getStateId($state); SimpleSAML\Logger::debug('authlinkedin auth state id = ' . $stateID); $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); // Get the request token $requestToken = $consumer->getRequestToken('https://api.linkedin.com/uas/oauth/requestToken', array('oauth_callback' => SimpleSAML\Module::getModuleUrl('authlinkedin') . '/linkback.php?stateid=' . $stateID)); SimpleSAML\Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); $state['authlinkedin:requestToken'] = $requestToken; // Update the state SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); // Authorize the request token $consumer->getAuthorizeRequest('https://www.linkedin.com/uas/oauth/authenticate', $requestToken); }
/** * Log-in using Facebook platform * * @param array &$state Information about the current authentication. */ public function authenticate(&$state) { assert('is_array($state)'); /* We are going to need the authId in order to retrieve this authentication source later. */ $state[self::AUTHID] = $this->authId; $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); // SimpleSAML_Logger::debug('facebook auth state id = ' . $stateID); $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); // Get the request token $requestToken = $consumer->getRequestToken('http://twitter.com/oauth/request_token'); SimpleSAML_Logger::debug("Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); $oauthState = array('requestToken' => serialize($requestToken), 'stateid' => $stateID); $session = SimpleSAML_Session::getInstance(); $session->setData('oauth', 'oauth', $oauthState); // Authorize the request token $consumer->getAuthorizeRequest('http://twitter.com/oauth/authenticate', $requestToken); }
{ echo $prompt; return rtrim(fgets(STDIN), "\n"); } /* This is the base directory of the simpleSAMLphp installation. */ $baseDir = dirname(dirname(dirname(dirname(__FILE__)))); /* Add library autoloader. */ require_once $baseDir . '/lib/_autoload.php'; require_once dirname(dirname(__FILE__)) . '/libextinc/OAuth.php'; // Needed in order to make session_start to be called before output is printed. $session = SimpleSAML_Session::getInstance(); $baseurl = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'https://foodle.feide.no/simplesaml'; $key = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'key'; $secret = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : 'secret'; echo 'Welcome to the OAuth CLI client' . "\n"; $consumer = new sspmod_oauth_Consumer($key, $secret); // 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); 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"; $userdata = $consumer->getUserInfo($baseurl . '/module.php/oauth/getUserInfo.php', $accessToken); echo 'You are successfully authenticated to this Command Line CLI. ' . "\n"; echo 'Got data [' . join(', ', array_keys($userdata)) . ']' . "\n"; echo 'Your user ID is : ' . $userdata['eduPersonPrincipalName'][0] . "\n";
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; }
} # module.php/virtualorg/data_oauth_json.php $baseurl = 'http://vo.rnd.feide.no/simplesaml/'; $key = 'key'; $secret = 'secret'; $consumer = new sspmod_oauth_Consumer($key, $secret); if (isset($_REQUEST['step']) && $_REQUEST['step'] == '1') { $oauthsess = SimpleSAML_Utilities::generateID(); // Get the request token $requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/requestToken.php'); #print_r($requestToken); exit; $session->setData('oauthSess', $oauthsess, serialize($requestToken)); # echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n"; $callback = SimpleSAML_Utilities::addURLparameter(SimpleSAML_Utilities::selfURLNoQuery(), array('step' => '2', 'oauthsess' => $oauthsess)); // Authorize the request token $url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, TRUE, $callback); # echo('Go to this URL to authenticate/authorize the request: ' . $url . "\n"); } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '2') { $requestToken = unserialize($session->getData('oauthSess', $_REQUEST['oauthsess'])); # print_r($requestToken); exit; // Replace the request token with an access token $accessToken = $consumer->getAccessToken($baseurl . '/module.php/oauth/accessToken.php', $requestToken); $session->setData('accessToken', 'accesstoken', serialize($accessToken)); SimpleSAML_Utilities::redirect('index.php?step=3'); exit; } if ($adata = $session->getData('accessToken', 'accesstoken')) { $accessToken = unserialize($adata); $vomemberships = $consumer->getUserInfo($baseurl . '/module.php/virtualorg/data_oauth_json.php?method=memberOf', $accessToken); $voreceived = TRUE; $accessTokenKey = $accessToken->key;