daviddesberg / PHPoAuthLib

PHP 5.3+ oAuth 1/2 Client Library
Other
1.09k stars 454 forks source link

Vkontakte provider error #341

Open IdenGit opened 9 years ago

IdenGit commented 9 years ago

When Vkontakte provider run requestAccessToken from abstract service Stream Client fall down. Vk use specify grant_type - client_credentials. So i add fixed requestAccessToken method to Vkontakte.php class.

Vkontakte.php

#line 105
protected function getAuthorizationMethod()
    {
        return static::AUTHORIZATION_METHOD_QUERY_STRING;
    }
# redeclare AbstractService requestAccessToken
public function requestAccessToken($code, $state = null) 
    {
        if (null !== $state) {
            $this->validateAuthorizationState($state);
        }

        $bodyParams = array(
            'code'          => $code,
            'client_id'     => $this->credentials->getConsumerId(),
            'client_secret' => $this->credentials->getConsumerSecret(),
            'redirect_uri'  => $this->credentials->getCallbackUrl(),
            'grant_type'    => 'client_credentials',
        );

        $responseBody = $this->httpClient->retrieveResponse(
            $this->getAccessTokenEndpoint(),
            $bodyParams,
            $this->getExtraOAuthHeaders()
        );

        $token = $this->parseAccessTokenResponse($responseBody);
        $this->storage->storeAccessToken($this->service(), $token);

        return $token;
    }

Please fix this bug.

kusmierz commented 9 years ago

anyway - how could I easily change grant_type to other values (password, client_credentials and so on)? Maybe \OAuth\Common\Consumer\Credentials itself should have another property "grant_type", ie. accessTokenGrantType and refreshAccessTokenGrantType?

IdenGit commented 9 years ago

Sounds good!

logical-and commented 9 years ago

Can you reproduce the error on my fork?

logical-and commented 9 years ago

@kusmierz @IdenGit Any news guys?