question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid Grant Parameter

See original GitHub issue

When I run the code:

CLIENT_ID="amzn1.application-oa2-client.2ce85ab0db2d4e9..."
CLIENT_SECRET="4247e7121f974bd0dc964d99e3dfa445b8572e..."
CODE="ANudVcrBPTyYrgKMHhtu"
GRANT_TYPE="authorization_code"
REDIRECT_URI="https://localhost:9745/authresponse"

curl -X POST --data "grant_type=${GRANT_TYPE}&code=${CODE}&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URI}" https://api.amazon.com/auth/o2/token

i get the following error: {"error_description":"The request has an invalid grant parameter : code","error":"invalid_grant"} can anyone help me?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
NilSkilzcommented, Sep 13, 2017

Just to document my process somewhat…

The Amazon UI has changed a fair bit when creating the ‘device’. But it’s easy enough to muddle through that part. I used this page: https://sakirtemel.github.io/MMM-alexa/ to generate the ‘Code’. You need to add https://sakirtemel.github.io/MMM-alexa/ to the list of Redirect URLs for your device in the AVS product.

Once I had the ‘Code’ I used a REST console in Chrome (https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo)

The url: https://api.amazon.com/auth/o2/token Select POST, Data Form then add your parameters for: client_id client_secret code grant_type redirect_uri

I discovered two things at this point.

  1. The ‘Code’ generated is linked to the redirect_uri - so it needs to be the same one, in this case https://sakirtemel.github.io/MMM-alexa/ (Use this as it’s url encoded: https%3A%2F%2Fsakirtemel.github.io%2FMMM-alexa%2F)
  2. The code is single use, so if something goes wrong and it doesn’t work, you’ll need to generate a new code to try again.

From that I got the refresh_token.

I have to say, I’ve not got it working properly yet - but I haven’t had time to debug what’s going on (could be mic issue etc). So let me know if anyone does all this and gets it to work!

On 23 Aug 2017, at 12:49, Dolan notifications@github.com wrote:

Thanks @NilSkilz https://github.com/nilskilz I will update the guide to make it more clear

Did the Alexa helper website not help at all?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dolanmiu/MMM-awesome-alexa/issues/14#issuecomment-324304920, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTmPbmDwSwTrwqwT1af_hKQ6drJ-o7Nks5sbBHWgaJpZM4Oifkq.

2reactions
NilSkilzcommented, Aug 22, 2017

In case anyone comes across this. I managed to get it working. One thing to note is that the ‘code’ you receive from Amazon expires when you try to use it, whether you receive back an access token or not. Also, the redirect_uri must be the same as the one you used to grant the initial code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The request has an invalid grant parameter : refresh_token ...
The spapi oauth code which is used to generate the refresh token is a short lived token valid only for 5 minutes. This...
Read more >
"invalid_grant" error when requesting an OAuth Token
Issue symptoms. When I attempt to obtain an access token, I receive the error below. {"error":"invalid_grant",
Read more >
question - Amazon Developer Forums - AnswerHub
Invalid grant parameter : refresh_token for api.amazonalexa.com/v2 query · Request Type: POST · data: { · 'refresh_token': 'Atza|IwEBIF5...', # Same ...
Read more >
Google OAuth “invalid_grant” nightmare — and how to fix it
A token that hasn't been used for 6 months automatically expires. As many of our users that got the “invalid_grant” error was created...
Read more >
How to get an access token with Auth Code Grant | DocuSign
This topic demonstrates how to manually generate an access token using Authorization Code Grant authentication or with a refresh token.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found