【发布时间】:2021-04-03 03:59:11
【问题描述】:
尽管我在 Stackoverflow 上阅读了许多重复的问题,但我仍然无法终生弄清楚我做错了什么。
问题:我成功接收到授权码,但是当我使用此码请求访问令牌时,出现以下错误:
{
"error": "invalid_request",
"error_description": "Invalid parameter value for redirect_uri: Missing scheme: http%3A%2F%2Flocalhost%3A3030%2Fgoogle%2Foauth2%2Fcallback"
}
配置:
-
我使用 http://localhost:3030/google/oauth2/callback 作为回调 URL
-
这是我发送以获取令牌的“原始 curl”请求:
curl --location --request POST 'https://oauth2.googleapis.com/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'code=4%2F0AY0e-g6zyewnsWjPEXoxZWawsp1E634ZlefYoBeYO1nXxBwjPQNCGVf7SGb4MxfNcjUApw' \ --data-urlencode 'redirect_uri=http%3A%2F%2Flocalhost%3A3030%2Fgoogle%2Foauth2%2Fcallback' \ --data-urlencode 'client_id=....' \ --data-urlencode 'client_secret=....' \ --data-urlencode 'grant_type=authorization_code'附:如您所见,我“UrlEncoded”
redirect_url以及code因为它确实包含斜杠。为了站在同一边,我尝试对client_id、client_secret和grant_type进行编码,但由于它们只包含 ASCII 字符,所以它们的输出相同。
我做了什么:
-
在 SO 上通过类似问题进行研究:jenkins issue、ios issue、php issue、missing http issue、nodejs issue - similar to this one 随后是discussion、this、that 以及所有其他出现在这里的问题- 为简洁起见将省略它们。
-
我试过设置
-
http://localhost/google/oauth2/callback:3030以及 -
http://127.0.0.1:3030/google/oauth2/callback和 -
http://127.0.0.1/google/oauth2/callback:3000(虽然最后指定一个端口非常奇怪,将 localhost 更改为 127.0.0.1,但在其中一个类似线程中提出了建议),这些都不起作用。
-
-
阅读所有文档from google
-
在 OAuth2 Playground 上玩过(它显然可以工作),但对我不起作用
-
尝试了 body + 不同内容类型的多种变体同样的问题,但有时我也得到了
{ "error": "invalid_grant", "error_description": "Bad Request" }
任何帮助将不胜感激。
【问题讨论】: