最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fix 'error: invalid_grant Invalid authorization code' when asking for reshresh_token from Sp

programmeradmin3浏览0评论

I'm trying to receive refresh_token for my Ionic app, I successfully receive access_token.

I receive code (authorization_code or access_token) from endpoint = in my TypeScript project, I pass it to cURL to test how to get refresh_token but the only thing which I receive its error.

curl -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic MzBhNT...ZWIyZWQ=" -d grant_type=authorization_code -d code=BQAjgZOFne3p8PB4ARJkrXtq...kI4xJvhQ7SutZoJqVWILCY -d redirect_uri=http%3A%2F%2Flocalhost%3A8100%2Fmain -X POST 

Expected output:

{
   "access_token": "NgCXRK...MzYjw",
   "token_type": "Bearer",
   "scope": ...,
   "expires_in": 3600,
   "refresh_token": "NgAagA...Um_SHo"
}

But received error:

{"error":"invalid_grant","error_description":"Invalid authorization code"}

I'm trying to receive refresh_token for my Ionic app, I successfully receive access_token.

I receive code (authorization_code or access_token) from endpoint https://accounts.spotify./authorize?client_id= in my TypeScript project, I pass it to cURL to test how to get refresh_token but the only thing which I receive its error.

curl -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic MzBhNT...ZWIyZWQ=" -d grant_type=authorization_code -d code=BQAjgZOFne3p8PB4ARJkrXtq...kI4xJvhQ7SutZoJqVWILCY -d redirect_uri=http%3A%2F%2Flocalhost%3A8100%2Fmain -X POST https://accounts.spotify./api/token

Expected output:

{
   "access_token": "NgCXRK...MzYjw",
   "token_type": "Bearer",
   "scope": ...,
   "expires_in": 3600,
   "refresh_token": "NgAagA...Um_SHo"
}

But received error:

{"error":"invalid_grant","error_description":"Invalid authorization code"}
Share Improve this question asked Aug 23, 2019 at 0:07 user3057645user3057645 3311 gold badge3 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

So after two days of trying I found this issue and after checking documentation I found where I was wrong. The thing is when you want to refresh token you need to send in body of POST request to /api/token endpoint code not access_token. In my case I was sending access_token. To receive code you should send same request to https://accounts.spotify./authorize endpoint but with parameter response_type=code.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论