Getting "Authorization permission type not supported by authorization server" from amazon

I am trying to get an access token, I am not getting this error

{"error_description": "Authorization permission 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);
+4
source share
2 answers

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

Here’s from Amazon’s developer documentation: "Request an access token ... The type of token returned. Must be a medium."

"Response to access token: ... unsupported_grant_type The client specified an invalid token_type."

+1

CURLOPT_HTTPHEADER

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

to

Content-Type: application/json

+1

Source: https://habr.com/ru/post/1660764/


All Articles