本文整理汇总了PHP中SimpleSAML_Auth_State::getStateId方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleSAML_Auth_State::getStateId方法的具体用法?PHP SimpleSAML_Auth_State::getStateId怎么用?PHP SimpleSAML_Auth_State::getStateId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleSAML_Auth_State
的用法示例。
在下文中一共展示了SimpleSAML_Auth_State::getStateId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finalStep
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: authenticate
/**
* 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);
}