本文整理汇总了PHP中League\OAuth2\Client\Provider\AbstractProvider::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractProvider::getAccessToken方法的具体用法?PHP AbstractProvider::getAccessToken怎么用?PHP AbstractProvider::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\OAuth2\Client\Provider\AbstractProvider
的用法示例。
在下文中一共展示了AbstractProvider::getAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* {@inheritdoc}
*/
public function authenticate(RequestInterface $request)
{
// TODO: add error handling
// TODO: support other grant types?
$accessToken = $this->provider->getAccessToken('client_credentials');
return $request->withHeader('Authorization', 'Bearer ' . $accessToken);
}
示例2: getAccessToken
/**
* Provides support for token renewal instead of token refreshing.
*
* {@inheritdoc}
*
* @return AccessToken
*/
public function getAccessToken($grant = 'authorization_code', $params = [])
{
if ($grant === 'refresh_token' || $grant instanceof RefreshToken) {
throw new \InvalidArgumentException('Square does not support refreshing tokens, please use renew_token instead');
}
if (is_string($grant) && $grant === 'renew_token') {
$grant = new RenewToken();
}
if (!$grant instanceof RenewToken) {
return parent::getAccessToken($grant, $params);
}
$requestParams = $grant->prepRequestParams([], $params);
$headers = ['Authorization' => 'Client ' . $this->clientSecret, 'Accept' => 'application/json'];
try {
$request = $this->getHttpClient()->post($this->urlRenewToken(), $headers)->setBody(json_encode($requestParams), 'application/json')->send();
$response = $request->getBody();
} catch (BadResponseException $e) {
// @codeCoverageIgnoreStart
$response = $e->getResponse()->getBody();
// @codeCoverageIgnoreEnd
}
$result = json_decode($response, true);
if (!empty($result['error']) || !empty($e)) {
// @codeCoverageIgnoreStart
throw new IDPException($result);
// @codeCoverageIgnoreEnd
}
$result = $this->prepareAccessTokenResult($result);
return $grant->handleResponse($result);
}
示例3: getAccessToken
/**
* @param $grant
* @param array $params
*/
public function getAccessToken($grant = 'authorization_code', array $params = [])
{
if (isset($params['refresh_token'])) {
throw new LightspeedProviderException('Lightspeed does not support token refreshing.');
}
return parent::getAccessToken($grant, $params);
}
示例4: getAccessToken
public function getAccessToken($grant, array $options = [])
{
if ($this->authWithResource) {
$options['resource'] = $this->resource ? $this->resource : $this->urlAPI;
}
return parent::getAccessToken($grant, $options);
}
示例5: getAccessToken
public function getAccessToken($grant = 'client-credentials', $params = [])
{
$token = unserialize($this->cache->load(self::TOKEN_KEY));
if (!$token) {
$token = parent::getAccessToken($grant, $params);
$this->cache->save(serialize($token), self::TOKEN_KEY, [], $token->expires - time());
}
return $token;
}
示例6: getAccessToken
/**
* Get an access token from the OAuth provider.
*
* @param string $grantType One of the following:
* - 'authorization_code'
* - 'password'
* - 'refresh_token'
* @param array $options
* @param string $code
*
* @return AccessToken
*/
protected function getAccessToken($grantType, array $options)
{
// Try to get an access token using the authorization code grant.
$accessToken = $this->provider->getAccessToken($grantType, $options);
$this->setDebugMessage('OAuth token received: ' . json_encode($accessToken));
try {
$accessToken->hasExpired();
return $accessToken;
} catch (\RuntimeException $e) {
return new AccessToken(['access_token' => $accessToken->getToken(), 'resource_owner_id' => $accessToken->getResourceOwnerId(), 'refresh_token' => $accessToken->getRefreshToken(), 'expires_in' => 3600]);
}
}
示例7: handle
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface|RedirectResponse
*/
public function handle(Request $request)
{
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
$this->provider = $this->getProvider($redirectUri);
$session = $request->getAttribute('session');
$queryParams = $request->getQueryParams();
$code = array_get($queryParams, 'code');
$state = array_get($queryParams, 'state');
if (!$code) {
$authUrl = $this->provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
$session->set('oauth2state', $this->provider->getState());
return new RedirectResponse($authUrl . '&display=popup');
} elseif (!$state || $state !== $session->get('oauth2state')) {
$session->forget('oauth2state');
echo 'Invalid state. Please close the window and try again.';
exit;
}
$this->token = $this->provider->getAccessToken('authorization_code', compact('code'));
$owner = $this->provider->getResourceOwner($this->token);
$identification = $this->getIdentification($owner);
$suggestions = $this->getSuggestions($owner);
return $this->authResponse->make($request, $identification, $suggestions);
}
示例8: getAccessToken
/**
* Call this after the user is redirected back to get the access token.
*
* @return \League\OAuth2\Client\Token\AccessToken
*
* @throws InvalidStateException
* @throws MissingAuthorizationCodeException
* @throws IdentityProviderException If token cannot be fetched
*/
public function getAccessToken()
{
if (!$this->isStateless) {
$expectedState = $this->getSession()->get(self::OAUTH2_SESSION_STATE_KEY);
$actualState = $this->getCurrentRequest()->query->get('state');
if (!$actualState || $actualState !== $expectedState) {
throw new InvalidStateException('Invalid state');
}
}
$code = $this->getCurrentRequest()->get('code');
if (!$code) {
throw new MissingAuthorizationCodeException('No "code" parameter was found (usually this is a query parameter)!');
}
return $this->provider->getAccessToken('authorization_code', ['code' => $code]);
}
示例9: getAccessToken
public function getAccessToken($grant = 'authorization_code', $params = [])
{
return parent::getAccessToken($grant, $params);
}
示例10: getAccessToken
public function getAccessToken($grant, array $params = [])
{
return parent::getAccessToken($grant, $params);
}
示例11: getAccessToken
/**
* {@inheritDoc}
*
* @see https://github.com/reddit/reddit/wiki/OAuth2
*/
public function getAccessToken($grant = "authorization_code", $params = [])
{
// Allow Reddit-specific 'installed_client' to be specified as a string,
// keeping consistent with the other grant types.
if ($grant === "installed_client") {
$grant = new InstalledClient();
}
return parent::getAccessToken($grant, $params);
}
示例12: getAccessToken
/**
* Capturar accessToken.
* @param mixed $grant
* @param array $options
* @return AccessToken
*/
public function getAccessToken($grant, array $options = [])
{
return $this->token = parent::getAccessToken($grant, $options);
}
示例13: getAccessToken
/**
* @inheritdoc
*/
public function getAccessToken($grant = 'authorization_code', array $params = [])
{
if (!isset($params['resource'])) {
// Set to default Access Token Resource
$params['resource'] = self::ACCESS_TOKEN_RESOURCE;
}
return parent::getAccessToken($grant, $params);
}
示例14: testInvalidGrantObject
/**
* @expectedException InvalidArgumentException
*/
public function testInvalidGrantObject()
{
$grant = new \StdClass();
$this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']);
}
示例15: getAccessToken
public function getAccessToken($grant = 'authorization_code', $params = [])
{
$params['type'] = 'web_server';
return parent::getAccessToken($grant, $params);
}