buildAuthUrl() public method

Composes user authorization URL.
public buildAuthUrl ( OAuthToken $requestToken = null, array $params = [] ) : string
$requestToken OAuthToken OAuth request token.
$params array additional request params.
return string authorize URL
 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!');
 }
Example #2
0
 /**
  * @return string
  * @throws Exception
  */
 public function getAuthorizationUri()
 {
     if ($this->service instanceof OAuth1) {
         $token = $this->service->fetchRequestToken();
         $authorizationUri = $this->service->buildAuthUrl($token);
     } elseif ($this->service instanceof OAuth2) {
         $authorizationUri = $this->service->buildAuthUrl();
     } else {
         throw new Exception(Yii::t('SyncSocial', 'SyncSocial is not support {serviceName}.', ['serviceName' => get_class($this->service)]));
     }
     return $authorizationUri;
 }
 /**
  * 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);
     }
 }