protected function authOAuth2($client, $authUrlParams = [])
    {
        $request = Yii::$app->getRequest();

        if (($error = $request->get('error')) !== null) {
            if (
                $error === 'access_denied' ||
                $error === 'user_cancelled_login' ||
                $error === 'user_cancelled_authorize'
            ) {
                // user denied error
                return $this->authCancel($client);
            }
            // request error
            $errorMessage = $request->get('error_description', $request->get('error_message'));
            if ($errorMessage === null) {
                $errorMessage = http_build_query($request->get());
            }
            throw new Exception('Auth error: ' . $errorMessage);
        }

        // Get the access_token and save them to the session.
        if (($code = $request->get('code')) !== null) {
            $token = $client->fetchAccessToken($code);
            if (!empty($token)) {
                return $this->authSuccess($client);
            }
            return $this->authCancel($client);
        }

        $url = $client->buildAuthUrl($authUrlParams);
        return Yii::$app->getResponse()->redirect($url);
    }
protected function authOAuth2($client, $authUrlParams = [])
    {
        $request = Yii::$app->getRequest();

        if (($error = $request->get('error')) !== null) {
            if (
                $error === 'access_denied' ||
                $error === 'user_cancelled_login' ||
                $error === 'user_cancelled_authorize'
            ) {
                // user denied error
                return $this->authCancel($client);
            }
            // request error
            $errorMessage = $request->get('error_description', $request->get('error_message'));
            if ($errorMessage === null) {
                $errorMessage = http_build_query($request->get());
            }
            throw new Exception('Auth error: ' . $errorMessage);
        }

        // Get the access_token and save them to the session.
        if (($code = $request->get('code')) !== null) {
            $token = $client->fetchAccessToken($code);
            if (!empty($token)) {
                return $this->authSuccess($client);
            }
            return $this->authCancel($client);
        }

        $url = $client->buildAuthUrl($authUrlParams);
        return Yii::$app->getResponse()->redirect($url);
    }
protected function authOAuth2 ( $ client , $ authUrlParams = [ ] ) { $ request = Yii :: $ app -> getRequest ( ) ; if ( ( $ error = $ request -> get ( 'error' ) ) !== null ) { if ( $ error === 'access_denied' || $ error === 'user_cancelled_login' || $ error === 'user_cancelled_authorize' ) { // user denied error return $ this -> authCancel ( $ client ) ; } // request error $ errorMessage = $ request -> get ( 'error_description' , $ request -> get ( 'error_message' ) ) ; if ( $ errorMessage === null ) { $ errorMessage = http_build_query ( $ request -> get ( ) ) ; } throw new Exception ( 'Auth error: ' . $ errorMessage ) ; } // Get the access_token and save them to the session. if ( ( $ code = $ request -> get ( 'code' ) ) !== null ) { $ token = $ client -> fetchAccessToken ( $ code ) ; if ( ! empty ( $ token ) ) { return $ this -> authSuccess ( $ client ) ; } return $ this -> authCancel ( $ client ) ; } $ url = $ client -> buildAuthUrl ( $ authUrlParams ) ; return Yii :: $ app -> getResponse ( ) -> redirect ( $ url ) ; }
Performs OAuth2 auth flow.
@param OAuth2 $client auth client instance.
@param array $authUrlParams additional auth GET params.
@return Response action response.
@throws \yii\base\Exception on failure.
Performs OAuth2 auth flow .