ricbra / php-discogs-api

PHP 5.4 Implementation of the Discogs API
MIT License
152 stars 95 forks source link

oauth actually working? #18

Closed schnubor closed 10 years ago

schnubor commented 10 years ago

I've obtained an access token + secret from discogs but can't seem to get the following working altough it does work with other (more complicated) clients:

$client = Discogs\ClientFactory::factory([
    'defaults' => [
        'headers' => ['User-Agent' => 'diskollect/0.1 +http://beta.diskollect.com'],
    ]
]);

$oauth = new GuzzleHttp\Subscriber\Oauth\Oauth1([
    'consumer_key'    => $_ENV['DC_CONSUMER_KEY'], // from Discogs developer page
    'consumer_secret' => $_ENV['DC_CONSUMER_SECRET'], // from Discogs developer page
    'token'           => $user->discogs_access_token, // valid
    'token_secret'    => $user->discogs_access_token_secret // valid
]);
$client->getHttpClient()->getEmitter()->attach($oauth);

$identity = $client->getOAuthIdentity();

following exception is thrown:

GuzzleHttp \ Command \ Exception \ CommandClientException Error executing command: Client error response [url] http://api.discogs.com/oauth/identity [status code] 401 [reason phrase] Unauthorized

So after reading the https://github.com/guzzle/oauth-subscriber instructions I added the ['auth' => 'oauth'] param to the getOAuthIdentity method in service.php:

'getOAuthIdentity' => [
    'httpMethod' => 'GET',
    'uri' => 'oauth/identity',
    'responseModel' => 'GetResponse',
    'auth' => 'oauth',
]

But still no luck. The oauth object itself is filled with the correct values. I'm using Laravel as a framework. I'm not sure if I'm doing something wrong here. Any ideas?

ricbra commented 10 years ago

I've already added 'auth' => 'oath' to the client via the ClientFactory. It should work out of the box with the plugin. Could you dump your request to check if the oauth values are present like in the fixture for the tests (oauth_identity)?

I'll upload my Symfony2 sandbox tonight for testing OAuth. It works using the HWIOAuthBundle, which supports OAuth 1.0a.

schnubor commented 10 years ago

Thanks. After double checking the request body I noticed the sent token was wrong. Refreshed all my tokens and now it's working. Sorry for the trouble.