跨平台Google OAuth登录:redirect_uri不匹配

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

我使用Google OAuth对我的应用程序上的用户进行身份验证,并面临redirect_uri支持多个客户端应用程序的问题。

在服务器端,我提供了一个使用Google PHP SDK的REST API,登录流程几乎与此处描述的类似:https://developers.google.com/identity/sign-in/web/server-side-flow

我有两个客户端应用程序:使用JavaScript SDK的网站和使用Android客户端的Android应用程序,实现为https://developers.google.com/identity/sign-in/android/start-integrating

我没有在Google控制台中配置redirect_uri。我的问题是我在我的服务器代码中将redirect_uri设置为postmessage,但我无法使用Android应用程序:我得到redirect_uri mismatch错误。

$this->client = new Google_Client;
$this->client->setRedirectUri('postmessage');

如果没有这个uri,我的Web客户端上的google登录会引发错误“获取OAuth2访问令牌时出错”消息:

invalid_request:缺少参数:redirect_uri

如果我没有指定redirect_uri,登录在Android上运行正常,但是Web客户端不起作用。我该如何解决这个问题?

php android oauth google-oauth2 google-signin
1个回答
1
投票

您需要将重定向uri设置如下:

  1. 如果它的web sdk将其设置为'postmessage'
  2. 如果它是移动的(在你的情况下为android)将其设置为''(空字符串)

从客户端传递某种标识符,以便您在服务器中知道应该设置哪个重定向uri。

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