getStateId() 공개 정적인 메소드

Note that this function will not save the state.
public static getStateId ( &$state, boolean $rawId = false ) : string
$rawId boolean Return a raw ID, without a restart URL. Defaults to FALSE.
리턴 string Identifier which can be used to retrieve the state later.
예제 #1
0
 public function finalStep(&$state)
 {
     assert('is_array($state)');
     $stateID = SimpleSAML_Auth_State::getStateId($state);
     SimpleSAML_Logger::debug("oauth wrap:  Using this verification code [" . $state['authwindowslive:wrap_verification_code'] . "]");
     // Retrieve Access Token
     // Documentation at:  http://msdn.microsoft.com/en-us/library/live/hh243641
     // http://msdn.microsoft.com/en-us/library/live/hh243647.aspx
     $auth_code = $state['authwindowslive:wrap_verification_code'];
     $redirect_uri = SimpleSAML_Module::getModuleUrl('authwindowslive') . '/linkback.php?wrap_client_state=' . urlencode($stateID);
     $fields = array('code' => urlencode($auth_code), 'client_id' => urlencode($this->key), 'client_secret' => urlencode($this->secret), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode('authorization_code'));
     $post = '';
     foreach ($fields as $key => $value) {
         $post .= $key . '=' . $value . '&';
     }
     $post = rtrim($post, '&');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://login.live.com/oauth20_token.srf');
     curl_setopt($curl, CURLOPT_POST, 5);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     $result = curl_exec($curl);
     curl_close($curl);
     $response = json_decode($result);
     $accesstoken = $response->access_token;
     SimpleSAML_Logger::debug('LIVE AccessToken: ' . $accesstoken);
     // $url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken.'';
     $url = 'https://apis.live.net/v5.0/me?access_token=' . $accesstoken . '';
     $xmlresponse = $this->curl_file_get_contents($url);
     SimpleSAML_Logger::debug('LIVE Response: ' . $xmlresponse);
     $xml = json_decode($xmlresponse, true);
     foreach ($xml as $key => $value) {
         SimpleSAML_Logger::debug('LIVE ' . $key . ':' . $value);
     }
     $attributes = array();
     $attributes['windowslive_uid'] = array($xml['id']);
     //$attributes['uid']=$attributes['windowslive_uid'];
     $attributes['windowslive_name'] = array($xml['name']);
     //$attributes['cn']=$attributes['windowslive_name'];
     $attributes['windowslive_first_name'] = array($xml['first_name']);
     //$attributes['givenName']=$attributes['windowslive_first_name'];
     $attributes['windowslive_last_name'] = array($xml['last_name']);
     //$attributes['sn']=$attributes['windowslive_last_name'];
     //$attributes['windowslive_link'] = array($xml['link']);
     $attributes['windowslive_email'] = array($xml['emails']['account']);
     //$attributes['mail']=$attributes['windowslive_email'];
     /*$attributes['windowslive_birth_month'] = array($xml['birth_month']);
     		$attributes['windowslive_gender'] = array($xml['gender']);
     		$attributes['windowslive_city'] = array($xml['addresses']['personal']['city']);
     		$attributes['windowslive_state'] = array($xml['addresses']['personal']['state']);
     		$attributes['windowslive_region'] = array($xml['addresses']['personal']['region']);
     		$attributes['windowslive_locale'] = array($xml['locale']);*/
     //$attributes['language']=$attributes['windowslive_locale'];
     //$attributes['windowslive_updated_time'] = array($xml['updated_time']);
     $attributes['windowslive_user'] = array($xml['id'] . '@live.com');
     $state['Attributes'] = $attributes;
 }
예제 #2
0
 /**
  * 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);
 }