yii\authclient\OAuth2::buildAuthUrl PHP Method

buildAuthUrl() public method

Composes user authorization URL.
public buildAuthUrl ( array $params = [] ) : string
$params array additional auth GET params.
return string authorization URL.
    public function buildAuthUrl(array $params = [])
    {
        $defaultParams = ['client_id' => $this->clientId, 'response_type' => 'code', 'redirect_uri' => $this->getReturnUrl(), 'xoauth_displayname' => Yii::$app->name];
        if (!empty($this->scope)) {
            $defaultParams['scope'] = $this->scope;
        }
        if ($this->validateAuthState) {
            $authState = $this->generateAuthState();
            $this->setState('authState', $authState);
            $defaultParams['state'] = $authState;
        }
        return $this->composeUrl($this->authUrl, array_merge($defaultParams, $params));
    }

Usage Example

 public function testBuildAuthUrl()
 {
     $oauthClient = new OAuth2();
     $authUrl = 'http://test.auth.url';
     $oauthClient->authUrl = $authUrl;
     $clientId = 'test_client_id';
     $oauthClient->clientId = $clientId;
     $returnUrl = 'http://test.return.url';
     $oauthClient->setReturnUrl($returnUrl);
     $builtAuthUrl = $oauthClient->buildAuthUrl();
     $this->assertContains($authUrl, $builtAuthUrl, 'No auth URL present!');
     $this->assertContains($clientId, $builtAuthUrl, 'No client id present!');
     $this->assertContains(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!');
 }
All Usage Examples Of yii\authclient\OAuth2::buildAuthUrl