I try to get refresh token from code. Here is curl I use:
curl --request POST --data "code=4/0AWtg..&client_id=977..&client_secret=GOC..&redirect_uri=htt..&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
returned value is
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
What is wrong and how to get refresh_token from code, please? Thank you.
CodePudding user response:
invalid_grant is one of the most frequent oauth errors. It can be caused by a number of things.
- the code was already used
- your PC time isn't set to NTP
- The code and the client id don't match.
This is the code I use GoogleAuthenticationCurl.sh
curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=http://127.0.0.1&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token