PHP yii\authclient OAuthToken примеры использования

PHP yii\authclient OAuthToken - 10 примеров найдено. Это лучшие примеры PHP кода для yii\authclient\OAuthToken, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.
С версии: 2.0
Автор: Paul Klimov (klimov.paul@gmail.com)
Наследование: extends yii\base\Object
Пример #1
1
 /**
  * Gets new auth token to replace expired one.
  * @param OAuthToken $token expired auth token.
  * @return OAuthToken new auth token.
  */
 public function refreshAccessToken(OAuthToken $token)
 {
     $params = ['client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'refresh_token'];
     $params = array_merge($token->getParams(), $params);
     $response = $this->sendRequest('POST', $this->tokenUrl, $params);
     return $response;
 }
Пример #2
0
 /**
  * @depends testGetIsExpired
  */
 public function testGetIsValid()
 {
     $oauthToken = new OAuthToken();
     $expireDuration = 3600;
     $oauthToken->setExpireDuration($expireDuration);
     $this->assertFalse($oauthToken->getIsValid(), 'Empty token is valid!');
     $oauthToken->setToken('test_token');
     $this->assertTrue($oauthToken->getIsValid(), 'Filled up token is invalid!');
     $oauthToken->createTimestamp = $oauthToken->createTimestamp - ($expireDuration + 1);
     $this->assertFalse($oauthToken->getIsValid(), 'Expired token is valid!');
 }
Пример #3
0
 public function testBuildAuthUrl()
 {
     $oauthClient = new OAuth1();
     $authUrl = 'http://test.auth.url';
     $oauthClient->authUrl = $authUrl;
     $requestTokenToken = 'test_request_token';
     $requestToken = new OAuthToken();
     $requestToken->setToken($requestTokenToken);
     $builtAuthUrl = $oauthClient->buildAuthUrl($requestToken);
     $this->assertContains($authUrl, $builtAuthUrl, 'No auth URL present!');
     $this->assertContains($requestTokenToken, $builtAuthUrl, 'No token present!');
 }
Пример #4
0
 /**
  * @inheritdoc
  */
 public function fetchAccessToken(OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
 {
     $this->removeState('requestToken');
     $tokenConfig = ['class' => OAuthToken::className(), 'params' => ['oauth_token' => $this->token, 'oauth_token_secret' => $this->tokenSecret]];
     $token = Yii::createObject($tokenConfig);
     $this->setAccessToken($token);
     return $token;
 }
Пример #5
0
 /**
  * Gets new auth token to replace expired one.
  * @param OAuthToken $token expired auth token.
  * @return OAuthToken new auth token.
  */
 public function refreshAccessToken(OAuthToken $token)
 {
     $params = ['client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'refresh_token'];
     $params = array_merge($token->getParams(), $params);
     $request = $this->createRequest()->setMethod('POST')->setUrl($this->tokenUrl)->setData($params);
     $response = $this->sendRequest($request);
     $token = $this->createToken(['params' => $response]);
     $this->setAccessToken($token);
     return $token;
 }
Пример #6
0
 /**
  * Creates token from its configuration.
  * @param array $tokenConfig token configuration.
  * @return OAuthToken token instance.
  */
 protected function createToken(array $tokenConfig = [])
 {
     if (!array_key_exists('class', $tokenConfig)) {
         $tokenConfig['class'] = OAuthToken::className();
     }
     return Yii::createObject($tokenConfig);
 }
Пример #7
0
 /**
  * Handles token request response
  * @author Adegoke Obasa <goke@cottacush.com>
  * @param OAuthToken $response
  * @return mixed
  * @throws Oauth2ClientException
  */
 private function handleTokenResponse($response)
 {
     $params = $response->getParams();
     $status = ArrayHelper::getValue($params, 'status');
     if (!is_null($status) && $status == 'success') {
         $token = ArrayHelper::getValue($params, 'data');
         if (is_null($token)) {
             throw new Oauth2ClientException(self::CODE_NOT_SET);
         }
         return $token;
     } else {
         $message = ArrayHelper::getValue($params, 'message', self::DEFAULT_ERROR);
         throw new Oauth2ClientException($message);
     }
 }
Пример #8
0
 /**
  * @dataProvider apiUrlDataProvider
  *
  * @param $apiBaseUrl
  * @param $apiSubUrl
  * @param $expectedApiFullUrl
  */
 public function testApiUrl($apiBaseUrl, $apiSubUrl, $expectedApiFullUrl)
 {
     $oauthClient = $this->createOAuthClient();
     $oauthClient->expects($this->any())->method('apiInternal')->will($this->returnArgument(1));
     $accessToken = new OAuthToken();
     $accessToken->setToken('test_access_token');
     $accessToken->setExpireDuration(1000);
     $oauthClient->setAccessToken($accessToken);
     $oauthClient->apiBaseUrl = $apiBaseUrl;
     $this->assertEquals($expectedApiFullUrl, $oauthClient->api($apiSubUrl));
 }
Пример #9
0
 /**
  *
  * @param \yii\authclient\OAuthToken $accessToken
  * @param string  $url
  * @param string $method
  * @param array $params
  * @param array $headers
  */
 protected function apiInternal($accessToken, $url, $method, array $params, array $headers)
 {
     $headers[] = 'Authorization: Bearer ' . $accessToken->getToken();
     return $this->sendRequest($method, $url, $params, $headers);
 }
Пример #10
0
 /**
  * Performs request to the OAuth API.
  * @param OAuthToken $accessToken actual access token.
  * @param string $url absolute API URL.
  * @param string $method request method.
  * @param array $params request parameters.
  * @return array API response.
  * @throws Exception on failure.
  */
 protected function apiInternal($accessToken, $url, $method, array $params)
 {
     $params['oauth_consumer_key'] = $this->consumerKey;
     $params['oauth_token'] = $accessToken->getToken();
     $response = $this->sendSignedRequest($method, $url, $params);
     return $response;
 }