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
 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!');
 }
 /**
  * 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);
     }
 }
 /**
  * @return boolean
  */
 public function disconnect()
 {
     $this->service->setAccessToken(new OAuthToken());
     return !$this->isConnected();
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
 }
 /**
  * @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
 }