Gev Webf
Gev Webf

Reputation: 71

Getting "The authorization grant type is not supported by the authorization server" from amazon

I am trying getting access token but I'm getting this error

{"error_description":"The authorization grant type is not supported by the authorization server","error":"unsupported_grant_type"}

$code =  $_GET['code'];

$postfields = array(
    'grant_type'=>'authorization_code',
    'code'=>$code,
    'redirect_uri='=>'example/myTest.php',
    'client_id'=>'amzn1.application-oa2-client.xxxxxxxxxxx',
    'client_secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.amazon.com/auth/o2/token');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($httpRequest, CURLOPT_HEADER, 1);
// Edit: prior variable $postFields should be $postfields;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only!
$result = curl_exec($ch);

print_r($result);

Upvotes: 7

Views: 15646

Answers (3)

Rubislandy Rodriguez
Rubislandy Rodriguez

Reputation: 209

This is really old question but in the official documentation it says valid values are refresh_token and client_credentials.

Upvotes: 0

Mohamed El Tamimy
Mohamed El Tamimy

Reputation: 79

Change CURLOPT_HTTPHEADER from

Content-Type: application/x-www-form-urlencoded

to

Content-Type: application/json

Upvotes: 7

SergeyLebedev
SergeyLebedev

Reputation: 3708

Try to add 'token_type' => 'bearer' to your $postfields data.

Here is from Amazon developer documentation: "Access Token Request ... The type of token returned. Should be bearer."

"Access Token Response: ... unsupported_grant_type The client specified the wrong token_type."

Upvotes: 1

Related Questions