SimpleSAML_Auth_State::getStateId PHP Method

getStateId() public static method

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.
return string Identifier which can be used to retrieve the state later.
    public static function getStateId(&$state, $rawId = false)
    {
        assert('is_array($state)');
        assert('is_bool($rawId)');
        if (!array_key_exists(self::ID, $state)) {
            $state[self::ID] = SimpleSAML\Utils\Random::generateID();
        }
        $id = $state[self::ID];
        if ($rawId || !array_key_exists(self::RESTART, $state)) {
            // Either raw ID or no restart URL. In any case, return the raw ID.
            return $id;
        }
        // We have a restart URL. Return the ID with that URL.
        return $id . ':' . $state[self::RESTART];
    }

Usage Example

Example #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;
 }
All Usage Examples Of SimpleSAML_Auth_State::getStateId