当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractProvider::getAccessToken方法代码示例

本文整理汇总了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);
 }
开发者ID:godmodelabs,项目名称:flora-client-php-auth,代码行数:10,代码来源:OAuth2.php

示例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);
 }
开发者ID:wheniwork,项目名称:oauth2-square,代码行数:37,代码来源:Square.php

示例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);
 }
开发者ID:ursuleacv,项目名称:oauth2-lightspeed,代码行数:11,代码来源:Lightspeed.php

示例4: getAccessToken

 public function getAccessToken($grant, array $options = [])
 {
     if ($this->authWithResource) {
         $options['resource'] = $this->resource ? $this->resource : $this->urlAPI;
     }
     return parent::getAccessToken($grant, $options);
 }
开发者ID:thenetworg,项目名称:oauth2-azure,代码行数:7,代码来源:Azure.php

示例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;
 }
开发者ID:octahedron,项目名称:octasync-magento,代码行数:9,代码来源:Api.php

示例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]);
     }
 }
开发者ID:bolt,项目名称:Members,代码行数:24,代码来源:AbstractHandler.php

示例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);
 }
开发者ID:flarum,项目名称:core,代码行数:27,代码来源:AbstractOAuth2Controller.php

示例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]);
 }
开发者ID:knpuniversity,项目名称:oauth2-client-bundle,代码行数:24,代码来源:OAuth2Client.php

示例9: getAccessToken

 public function getAccessToken($grant = 'authorization_code', $params = [])
 {
     return parent::getAccessToken($grant, $params);
 }
开发者ID:piv915,项目名称:oauth2-vkontakte,代码行数:4,代码来源:Odnoklassniki.php

示例10: getAccessToken

 public function getAccessToken($grant, array $params = [])
 {
     return parent::getAccessToken($grant, $params);
 }
开发者ID:sergey-sla,项目名称:oauth2-odnoklassniki,代码行数:4,代码来源:Odnoklassniki.php

示例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);
 }
开发者ID:rtheunissen,项目名称:oauth2-reddit,代码行数:14,代码来源:Reddit.php

示例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);
 }
开发者ID:netforcews,项目名称:oauth-client,代码行数:10,代码来源:NetForce.php

示例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);
 }
开发者ID:81square,项目名称:oauth2-microsoft-graph,代码行数:11,代码来源:MicrosoftGraph.php

示例14: testInvalidGrantObject

 /**
  * @expectedException InvalidArgumentException
  */
 public function testInvalidGrantObject()
 {
     $grant = new \StdClass();
     $this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']);
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:8,代码来源:AbstractProviderTest.php

示例15: getAccessToken

 public function getAccessToken($grant = 'authorization_code', $params = [])
 {
     $params['type'] = 'web_server';
     return parent::getAccessToken($grant, $params);
 }
开发者ID:uberboom,项目名称:oauth2-basecamp,代码行数:5,代码来源:Basecamp.php


注:本文中的League\OAuth2\Client\Provider\AbstractProvider::getAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。