我们正在尝试实施Google的OAuth 2.0跨客户端登录功能,以便我们的服务器保留令牌并将其与用户关联,如此处的流程图所示:Google OAuth 2.0 Server-Side Flow
我能够在客户端应用上成功检索一次性访问代码。然后我通过帖子将该代码发送到服务器“http://example.com/oauth2callback/code=”
它到达服务器就好了。然后服务器尝试对Google进行POST,如下所示:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code={My Code}&
client_id={My Client ID}&
client_secret={My Client Secret}&
redirect_uri="http://example.com/oauth2callback"&
grant_type=authorization_code
但是,每次服务器返回“Error:redirect_uri_mismatch。”
我们已经尝试了一切。我们在Google控制台中仔细检查了redirect_uri匹配,并且客户端ID和客户端密钥是正确的。它仍然无法正常工作。有什么想法吗?
答案 0 :(得分:2)
在“服务器端”流程中,您的redirect_uri
应设置为postmessage
。不幸的是,Google没有明确记录。另请参阅Google OAuth 2.0 "error" : "redirect_uri_mismatch"及相关问题/答案。
答案 1 :(得分:0)
我们最终想出了这个,但我想在这里发布,以便其他人可以找到它。事实证明,如果您通过与自己服务器上的Google服务器通信来交换访问令牌的一次性访问代码,则不应指定重定向URI。相反,它应该是这样的:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code={My Code}&
client_id={My Client ID}&
client_secret={My Client Secret}&
redirect_uri=''&
grant_type=authorization_code