public function fetchAccessToken($oauthToken = null, OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
    {
        $incomingRequest = Yii::$app->getRequest();

        if ($oauthToken === null) {
            $oauthToken = $incomingRequest->get('oauth_token', $incomingRequest->post('oauth_token', $oauthToken));
        }

        if (!is_object($requestToken)) {
            $requestToken = $this->getState('requestToken');
            if (!is_object($requestToken)) {
                throw new InvalidParamException('Request token is required to fetch access token!');
            }
        }

        if (strcmp($requestToken->getToken(), $oauthToken) !== 0) {
            throw new HttpException(400, 'Invalid auth state parameter.');
        }

        $this->removeState('requestToken');

        $defaultParams = [
            'oauth_consumer_key' => $this->consumerKey,
            'oauth_token' => $requestToken->getToken()
        ];
        if ($oauthVerifier === null) {
            $oauthVerifier = $incomingRequest->get('oauth_verifier', $incomingRequest->post('oauth_verifier'));
        }
        if (!empty($oauthVerifier)) {
            $defaultParams['oauth_verifier'] = $oauthVerifier;
        }

        $request = $this->createRequest()
            ->setMethod($this->accessTokenMethod)
            ->setUrl($this->accessTokenUrl)
            ->setData(array_merge($defaultParams, $params));

        $this->signRequest($request, $requestToken);

        $response = $this->sendRequest($request);

        $token = $this->createToken([
            'params' => $response
        ]);
        $this->setAccessToken($token);

        return $token;
    }
public function fetchAccessToken($oauthToken = null, OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
    {
        $incomingRequest = Yii::$app->getRequest();

        if ($oauthToken === null) {
            $oauthToken = $incomingRequest->get('oauth_token', $incomingRequest->post('oauth_token', $oauthToken));
        }

        if (!is_object($requestToken)) {
            $requestToken = $this->getState('requestToken');
            if (!is_object($requestToken)) {
                throw new InvalidParamException('Request token is required to fetch access token!');
            }
        }

        if (strcmp($requestToken->getToken(), $oauthToken) !== 0) {
            throw new HttpException(400, 'Invalid auth state parameter.');
        }

        $this->removeState('requestToken');

        $defaultParams = [
            'oauth_consumer_key' => $this->consumerKey,
            'oauth_token' => $requestToken->getToken()
        ];
        if ($oauthVerifier === null) {
            $oauthVerifier = $incomingRequest->get('oauth_verifier', $incomingRequest->post('oauth_verifier'));
        }
        if (!empty($oauthVerifier)) {
            $defaultParams['oauth_verifier'] = $oauthVerifier;
        }

        $request = $this->createRequest()
            ->setMethod($this->accessTokenMethod)
            ->setUrl($this->accessTokenUrl)
            ->setData(array_merge($defaultParams, $params));

        $this->signRequest($request, $requestToken);

        $response = $this->sendRequest($request);

        $token = $this->createToken([
            'params' => $response
        ]);
        $this->setAccessToken($token);

        return $token;
    }
public function fetchAccessToken ( $ oauthToken = null , OAuthToken $ requestToken = null , $ oauthVerifier = null , array $ params = [ ] ) { $ incomingRequest = Yii :: $ app -> getRequest ( ) ; if ( $ oauthToken === null ) { $ oauthToken = $ incomingRequest -> get ( 'oauth_token' , $ incomingRequest -> post ( 'oauth_token' , $ oauthToken ) ) ; } if ( ! is_object ( $ requestToken ) ) { $ requestToken = $ this -> getState ( 'requestToken' ) ; if ( ! is_object ( $ requestToken ) ) { throw new InvalidParamException ( 'Request token is required to fetch access token!' ) ; } } if ( strcmp ( $ requestToken -> getToken ( ) , $ oauthToken ) !== 0 ) { throw new HttpException ( 400 , 'Invalid auth state parameter.' ) ; } $ this -> removeState ( 'requestToken' ) ; $ defaultParams = [ 'oauth_consumer_key' => $ this -> consumerKey , 'oauth_token' => $ requestToken -> getToken ( ) ] ; if ( $ oauthVerifier === null ) { $ oauthVerifier = $ incomingRequest -> get ( 'oauth_verifier' , $ incomingRequest -> post ( 'oauth_verifier' ) ) ; } if ( ! empty ( $ oauthVerifier ) ) { $ defaultParams [ 'oauth_verifier' ] = $ oauthVerifier ; } $ request = $ this -> createRequest ( ) -> setMethod ( $ this -> accessTokenMethod ) -> setUrl ( $ this -> accessTokenUrl ) -> setData ( array_merge ( $ defaultParams , $ params ) ) ; $ this -> signRequest ( $ request , $ requestToken ) ; $ response = $ this -> sendRequest ( $ request ) ; $ token = $ this -> createToken ( [ 'params' => $ response ] ) ; $ this -> setAccessToken ( $ token ) ; return $ token ; }
Fetches OAuth access token.
@param string $oauthToken OAuth token returned with redirection back to client.
@param OAuthToken $requestToken OAuth request token.
@param string $oauthVerifier OAuth verifier.
@param array $params additional request params.
@return OAuthToken OAuth access token.
@throws InvalidParamException on failure.
@throws HttpException in case oauth token miss-matches request token.
Fetches OAuth access token .