newuser-602b0c78-1658-45b6-86c0-266c86cf86b9 avatar image
newuser-602b0c78-1658-45b6-86c0-266c86cf86b9 asked ·

Login with Amazon button is not working in my website [error: unsupported_grant_type]

I'm trying to implement 'Login with amazon' button in my website. following are my code.

window.onAmazonLoginReady = function() {
(function(d) {
  var a = d.createElement('script'); a.type = 'text/javascript';
  a.async = true; = 'amazon-login-sdk';
  a.src = '';
document.getElementById('LoginWithAmazon').onclick = function() {
  options = {};
  options.scope = 'profile';
  options.response_type = 'code';
  amazon.Login.authorize(options, '');
  return false;

After executing above code, it redirects to ""
and having "code" and "Scope" as parameter.

By referring this Doc implemented the code in php to fetch "access_token" through curl call like below

if(isset($_REQUEST['code'])  && !empty($_REQUEST['code'])){
    $c = curl_init('');
    // $c = curl_init(''.$_REQUEST['code'].'&redirect_uri=');
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($c, CURLOPT_HTTPHEADER, 
        array(    'Authorization: Basic czzCaGRSa3F0MzpnWDFmQmF0M2JW',
                'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
                'client_id: amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                'client_secret: 8d2dbdcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf04d72a8')
    $data = array(
        'code' => $_REQUEST['code'],
        'redirect_uri' => '',
    $payload = json_encode($data);
    curl_setopt($c, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $r = curl_exec($c);
        echo 'Request Error:' . curl_error($c);
    $d = json_decode($r);
    echo "string";

but i'm getting error like "unsupported_grant_type"

stdClass Object (    [error_description] => The authorization grant type is not supported by the authorization server    [error] => unsupported_grant_type )

NOTE: I tried both GET and POST methods. In GET method getting empty page and for POST method the above error raising.

Any Luck?

login with amazonbuttons
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers