用于服务器端应用的Google登录:将有效授权码交换为令牌 - 错误请求错误(错误:redirect_uri_mismatch)

问题描述 投票:0回答:1

我正在尝试为我的应用程序实施Google Sign-In(https://developers.google.com/identity/sign-in/web/server-side-flow)。我成功获得了授权代码,但是当我尝试将其交换为令牌时,我得到以下响应。

错误响应:

{
    "error": "redirect_uri_mismatch",
    "error_description": "Bad Request"
}

我已经尝试向Google控制台添加一些重定向网址,但此问题仍然存在。请参阅下面的重定向网址。

http://localhost:49188/oauthcallback.aspx
https://localhost:49188/oauthcallback.aspx
https://localhost:49188/oauthcallback.aspx
http://localhost/oauthcallback.aspx
https://localhost/oauthcallback.aspx
http://localhost/oauthcallback.aspx
https://localhost/oauthcallback.aspx

我尝试过使用不同令牌端点的多个请求,但它无法解决此问题。

第一个终点:

POST URI: www.googleapis.com/oauth2/v4/token 
Content-Type: application/x-www-form-urlencoded

code={code}&
client_id={xxx}.apps.googleusercontent.com&
client_secret={client_secret}&
redirect_uri=https://localhost:49188/oauthcallback.aspx&
grant_type=authorization_code

第二个终点:

POST URI: https://oauth2.googleapis.com/token
Content-Type: application/x-www-form-urlencoded

code={code}&
client_id={xxx}.apps.googleusercontent.com&
client_secret={client_secret}&
redirect_uri=https://localhost:49188/oauthcallback.aspx&
grant_type=authorization_code

我希望获得正确的令牌响应,但请参考下面的JSON,因为它是我得到的响应。

预期回应:

{
  "access_token":"1/fFAGRNJru1FTz70BzhT3Zg",
  "expires_in":3920,
  "token_type":"Bearer",
  "refresh_token":"1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
}

错误响应

{
    "error": "redirect_uri_mismatch",
    "error_description": "Bad Request"
}
google-api google-signin google-openid google-identity googlesigninapi
1个回答
0
投票

@ user2705223你突出了一个好点。因此,如果您使用ux_mode =“popup”或默认值,似乎JS SDK将域主机添加为默认重定向URL而不是初始化时指定的URL,这非常奇怪。

© www.soinside.com 2019 - 2024. All rights reserved.