跨平台Google OAuth登录:redirect_uri不匹配 [英] Cross-platform Google OAuth Signin: redirect_uri mismatch

查看:204
本文介绍了跨平台Google OAuth登录:redirect_uri不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google OAuth对我的应用程序上的用户进行身份验证,并且遇到redirect_uri的问题以支持多个客户端应用程序.

I use Google OAuth for authenticating users on my application and face an issue with redirect_uri to support multiple client apps.

在服务器端,我提供了一个使用Google PHP SDK的REST API,登录流程几乎与此处描述的相似:

On the server-side, I provide a REST API which uses the Google PHP SDK, the login flow is almost similar to what's described here: https://developers.google.com/identity/sign-in/web/server-side-flow

我有两个客户端应用程序:一个使用JavaScript SDK的网站和一个使用android客户端的Android应用程序,实现为

I have two client apps: a website using the JavaScript SDK and an Android app using the android client, implemented as https://developers.google.com/identity/sign-in/android/start-integrating

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

I have no redirect_uri's configured in Google console. My issue is that I set the redirect_uri to postmessage in my server code, but I'm unable to get this working with the Android app: I get a redirect_uri mismatch error.

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

没有此uri,我的Web客户端上的google登录会抛出错误获取OAuth2访问令牌时出错,消息:

Without this uri, google login on my web client throws an error `Error fetching OAuth2 access token, message:

invalid_request:缺少参数:redirect_uri

invalid_request: Missing parameter: redirect_uri

如果我未指定redirect_uri,则登录在Android上可以正常使用,但Web客户端不起作用.我该如何解决?

If I do not specify a redirect_uri, login works fine on Android, but the web-client doesn't work. How do I workaround this?

推荐答案

您需要按如下所示设置重定向uri:

You need to set the redirect uri as following:

  1. 如果是网络SDK,请将其设置为'postmessage'
  2. 如果它是移动设备(在您的情况下为android),请将其设置为''(空字符串)
  1. If it's web sdk set it to 'postmessage'
  2. If it's mobile (android in your case) set it to '' (empty string)

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

Pass from the client some kind of identifier so you will know in the server which redirect uri you should set.

这篇关于跨平台Google OAuth登录:redirect_uri不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆