public function finalStep(&$state) { $requestToken = $state['authtwitter:authdata:requestToken']; $parameters = array(); if (!isset($_REQUEST['oauth_token'])) { throw new SimpleSAML_Error_BadRequest("Missing oauth_token parameter."); } if ($requestToken->key !== (string) $_REQUEST['oauth_token']) { throw new SimpleSAML_Error_BadRequest("Invalid oauth_token parameter."); } if (!isset($_REQUEST['oauth_verifier'])) { throw new SimpleSAML_Error_BadRequest("Missing oauth_verifier parameter."); } $parameters['oauth_verifier'] = (string) $_REQUEST['oauth_verifier']; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); SimpleSAML_Logger::debug("oauth: Using this request token [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); // Replace the request token with an access token $accessToken = $consumer->getAccessToken('https://api.twitter.com/oauth/access_token', $requestToken, $parameters); SimpleSAML_Logger::debug("Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]"); $userdata = $consumer->getUserInfo('https://api.twitter.com/1.1/account/verify_credentials.json', $accessToken); if (!isset($userdata['id_str']) || !isset($userdata['screen_name'])) { throw new SimpleSAML_Error_AuthSource($this->authId, 'Authentication error: id_str and screen_name not set.'); } $attributes = array(); foreach ($userdata as $key => $value) { if (is_string($value)) { $attributes['twitter.' . $key] = array((string) $value); } } $attributes['twitter_at_screen_name'] = array('@' . $userdata['screen_name']); $attributes['twitter_screen_n_realm'] = array($userdata['screen_name'] . '@twitter.com'); $attributes['twitter_targetedID'] = array('http://twitter.com!' . $userdata['id_str']); $state['Attributes'] = $attributes; }
public function finalStep(&$state) { $requestToken = unserialize($state['requestToken']); #echo '<pre>'; print_r($requestToken); exit; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); SimpleSAML_Logger::debug("oauth: Using this request token [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); // Replace the request token with an access token $accessToken = $consumer->getAccessToken('http://twitter.com/oauth/access_token', $requestToken); SimpleSAML_Logger::debug("Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]"); $userdata = $consumer->getUserInfo('http://twitter.com/account/verify_credentials.json', $accessToken); $attributes = array(); foreach ($userdata as $key => $value) { if (is_string($value)) { $attributes['twitter.' . $key] = array((string) $value); } } if (array_key_exists('screen_name', $userdata)) { $attributes['twitter_at_screen_name'] = array('@' . $userdata['screen_name']); $attributes['twitter_screen_n_realm'] = array($userdata['screen_name'] . '@twitter.com'); } if (array_key_exists('id_str', $userdata)) { $attributes['twitter_targetedID'] = array('http://twitter.com!' . $userdata['id_str']); } $state['Attributes'] = $attributes; }
public function finalStep(&$state) { $requestToken = unserialize($state['requestToken']); #echo '<pre>'; print_r($requestToken); exit; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); SimpleSAML_Logger::debug("oauth: Using this request token [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); // Replace the request token with an access token $accessToken = $consumer->getAccessToken('http://twitter.com/oauth/access_token', $requestToken); SimpleSAML_Logger::debug("Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]"); $userdata = $consumer->getUserInfo('http://twitter.com/account/verify_credentials.json', $accessToken); $attributes = array(); foreach ($userdata as $key => $value) { if (is_string($value)) { $attributes[$key] = array((string) $value); } } if (array_key_exists('screen_name', $userdata)) { $attributes['eduPersonPrincipalName'] = array('@' . $userdata['screen_name']); } if (array_key_exists('name', $userdata)) { $attributes['displayName'] = array($userdata['name']); } if (array_key_exists('profile_image_url', $userdata)) { $attributes['jpegPhoto'] = array(base64_encode(file_get_contents($userdata['profile_image_url']))); } if (array_key_exists('url', $userdata)) { $attributes['labeledURI'] = array($userdata['url']); } $state['Attributes'] = $attributes; }
public function finalStep(&$state) { $requestToken = $state['authmyspace:requestToken']; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); SimpleSAML_Logger::debug("oauth: Using this request token [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); // Replace the request token with an access token $accessToken = $consumer->getAccessToken('http://api.myspace.com/access_token', $requestToken); SimpleSAML_Logger::debug("Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]"); // API depricated on 20th September 2010 //$userdata = $consumer->getUserInfo('http://api.myspace.com/v1/user.json', $accessToken); // People API - http://developerwiki.myspace.com/index.php?title=People_API $userdata = $consumer->getUserInfo('http://api.myspace.com/1.0/people/@me/@self?fields=@all', $accessToken); $attributes = array(); if (is_array($userdata['person'])) { foreach ($userdata['person'] as $key => $value) { if (is_string($value) || is_int($value)) { $attributes['myspace.' . $key] = array((string) $value); } if (is_array($value)) { foreach ($value as $key2 => $value2) { if (is_string($value2) || is_int($value2)) { $attributes['myspace.' . $key . '.' . $key2] = array((string) $value2); } } } } if (array_key_exists('id', $userdata['person'])) { // person-id in the format of myspace.com.person.1234567890 if (preg_match('/(\\d+)$/', $userdata['person']['id'], $matches)) { $attributes['myspace_targetedID'] = array('http://myspace.com!' . $matches[1]); $attributes['myspace_uid'] = array($matches[1]); $attributes['myspace_user'] = array($matches[1] . '@myspace.com'); } } // profileUrl in the format http://www.myspace.com/username if (array_key_exists('profileUrl', $userdata['person'])) { if (preg_match('@/([^/]+)$@', $userdata['person']['profileUrl'], $matches)) { $attributes['myspace_username'] = array($matches[1]); $attributes['myspace_user'] = array($matches[1] . '@myspace.com'); } } } SimpleSAML_Logger::debug('MySpace Returned Attributes: ' . implode(", ", array_keys($attributes))); $state['Attributes'] = $attributes; }
public function finalStep(&$state) { $requestToken = $state['authlinkedin:requestToken']; $consumer = new sspmod_oauth_Consumer($this->key, $this->secret); SimpleSAML\Logger::debug("oauth: Using this request token [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]"); // Replace the request token with an access token (via GET method) $accessToken = $consumer->getAccessToken('https://api.linkedin.com/uas/oauth/accessToken', $requestToken, array('oauth_verifier' => $state['authlinkedin:oauth_verifier'])); SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" . $accessToken->key . "] with the secret [" . $accessToken->secret . "]"); $userdata = $consumer->getUserInfo('https://api.linkedin.com/v1/people/~:(' . $this->attributes . ')', $accessToken, array('http' => array('header' => 'x-li-format: json'))); $attributes = array(); foreach ($userdata as $key => $value) { if (is_string($value)) { $attributes['linkedin.' . $key] = array((string) $value); } } // TODO: pass accessToken: key, secret + expiry as attributes? if (array_key_exists('id', $userdata)) { $attributes['linkedin_targetedID'] = array('http://linkedin.com!' . $userdata['id']); $attributes['linkedin_user'] = array($userdata['id'] . '@linkedin.com'); } SimpleSAML\Logger::debug('LinkedIn Returned Attributes: ' . implode(", ", array_keys($attributes))); $state['Attributes'] = $attributes; }
{ 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";
// 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; # echo('<pre>'); print_r($vomemberships); exit; } $template = new SimpleSAML_XHTML_Template($config, 'virtualorgclient:client.tpl.php'); $template->data['vomemberships'] = $vomemberships; $template->data['voreceived'] = $voreceived; $template->data['accessToken'] = $accessTokenKey; $template->data['userid'] = $userid; $template->show();