本文整理汇总了PHP中OAuth\OAuth2\Service\AbstractService::requestAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractService::requestAccessToken方法的具体用法?PHP AbstractService::requestAccessToken怎么用?PHP AbstractService::requestAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth\OAuth2\Service\AbstractService
的用法示例。
在下文中一共展示了AbstractService::requestAccessToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkToken
/**
* Request access token
*
* This is the second step of oAuth authentication
*
* This implementation tries to abstract away differences between oAuth1 and oAuth2,
* but might need to be overwritten for specific services
*
* @return bool
*/
public function checkToken()
{
global $INPUT;
if (is_a($this->oAuth, 'OAuth\\OAuth2\\Service\\AbstractService')) {
/* oAuth2 handling */
if (!$INPUT->get->has('code')) {
return false;
}
$state = $INPUT->get->str('state', null);
try {
$this->oAuth->requestAccessToken($INPUT->get->str('code'), $state);
} catch (TokenResponseException $e) {
msg($e->getMessage(), -1);
return false;
}
} else {
/* oAuth1 handling */
if (!$INPUT->get->has('oauth_token')) {
return false;
}
$token = $this->storage->retrieveAccessToken($this->getServiceName());
// This was a callback request from BitBucket, get the token
try {
$this->oAuth->requestAccessToken($INPUT->get->str('oauth_token'), $INPUT->get->str('oauth_verifier'), $token->getRequestTokenSecret());
} catch (TokenResponseException $e) {
msg($e->getMessage(), -1);
return false;
}
}
return true;
}
示例2: checkToken
/**
* Request access token
*
* This is the second step of oAuth authentication
*
* This implementation tries to abstract away differences between oAuth1 and oAuth2,
* but might need to be overwritten for specific services
*
* @return bool
*/
public function checkToken()
{
global $INPUT;
if (is_a($this->oAuth, 'OAuth\\OAuth2\\Service\\AbstractService')) {
/* oAuth2 handling */
if (!$INPUT->get->has('code')) {
return false;
}
$state = $INPUT->get->str('state', null);
try {
$this->oAuth->requestAccessToken($INPUT->get->str('code'), $state);
} catch (TokenResponseException $e) {
msg($e->getMessage(), -1);
return false;
}
} else {
/* oAuth1 handling */
if (!$INPUT->get->has('oauth_token')) {
return false;
}
$token = $this->storage->retrieveAccessToken($this->getServiceName());
// This was a callback request from BitBucket, get the token
try {
$this->oAuth->requestAccessToken($INPUT->get->str('oauth_token'), $INPUT->get->str('oauth_verifier'), $token->getRequestTokenSecret());
} catch (TokenResponseException $e) {
msg($e->getMessage(), -1);
return false;
}
}
$validDomains = $this->hlp->getValidDomains();
if (count($validDomains) > 0) {
$userData = $this->getUser();
if (!$this->hlp->checkMail($userData['mail'])) {
msg(sprintf($this->hlp->getLang("rejectedEMail"), join(', ', $validDomains)), -1);
send_redirect(wl('', array('do' => 'login'), false, '&'));
}
}
return true;
}
示例3: requestAccessToken
/**
* Retrieves and stores the OAuth2 access token after a successful authorization.
*
* @param string $code The access code from the callback.
* @return TokenInterface $token
* @throws TokenResponseException
* @throws ErrorException
* @throws InvalidStateException
*/
public function requestAccessToken($code)
{
if (isset($this->state) && $this->service->getValidateState()) {
if (!isset($_GET['state']) || !$this->state->validateId($_GET['state'])) {
throw new InvalidStateException('The valid "state" argument required.');
}
}
return parent::requestAccessToken($code);
}