In order to acquire access token perform following sequence: ~~~ use yii\authclient\OAuth1; $oauthClient = new OAuth1(); $requestToken = $oauthClient->fetchRequestToken(); // Get request token $url = $oauthClient->buildAuthUrl($requestToken); // Get authorization URL return Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL After user returns at our site: $accessToken = $oauthClient->fetchAccessToken($requestToken); // Upgrade to access token ~~~
See also: http://oauth.net/
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends BaseOAuth
Exemplo n.º 1
1
 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!');
 }
Exemplo n.º 2
0
 /**
  * Performs OAuth1 auth flow.
  * @param OAuth1 $client auth client instance.
  * @return Response action response.
  */
 protected function authOAuth1($client)
 {
     // user denied error
     if (isset($_GET['denied'])) {
         return $this->redirectCancel();
     }
     if (isset($_REQUEST['oauth_token'])) {
         $oauthToken = $_REQUEST['oauth_token'];
     }
     if (!isset($oauthToken)) {
         // Get request token.
         $requestToken = $client->fetchRequestToken();
         // Get authorization URL.
         $url = $client->buildAuthUrl($requestToken);
         // Redirect to authorization URL.
         return Yii::$app->getResponse()->redirect($url);
     } else {
         // Upgrade to access token.
         $client->fetchAccessToken();
         return $this->authSuccess($client);
     }
 }
Exemplo n.º 3
0
 /**
  * @return boolean
  */
 public function disconnect()
 {
     $this->service->setAccessToken(new OAuthToken());
     return !$this->isConnected();
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function api($apiSubUrl, $method = 'GET', $data = [], $headers = [])
 {
     $format = ['format' => 'json', 'nojsoncallback' => 1];
     $params = array_merge($format, $data);
     return parent::api($apiSubUrl, $method, $params, $headers);
     // TODO: Change the autogenerated stub
 }