没有重定向uri的Android版Google登录如何工作? [英] How does Google Sign in for Android work without a redirect uri?

查看:70
本文介绍了没有重定向uri的Android版Google登录如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android上的Google登录库无需指定任何重定向uri就可以使用.为什么会这样呢?用户登录后,Google会将访问代码发送到哪个端点?以及如何将用户重定向回应用程序?

The Google Sign in library on Android works without specifying any redirect uri. Why is this the case? To which endpoint does Google send the access code to after the user logs in? And how does it redirect the user back to the app?

谢谢.

推荐答案

现在我知道,重定向uri实际上是应用程序本身,使用的uri指向应用程序上的页面,而不指向任何网站.可以使用以下信息在Android应用中设置重定向uri: https ://developer.android.com/training/app-links/deep-linking .我从这个youtube视频中学到了很多东西: https://www.youtube.com/watch?v = j3OTZ62AkNU

Now I see, the redirect uri is in fact the app itself, using a uri that points to a page on the app, not to any website. The redirect uri can be set up in the Android app by using the information here: https://developer.android.com/training/app-links/deep-linking. I learned a lot from this youtube video: https://www.youtube.com/watch?v=j3OTZ62AkNU

一旦将用户重定向回应用程序,则Google登录库将处理获取令牌和用户信息的情况.

Once it redirects the user back to the app, the google sign in library handles getting the token and user info.

com.googleusercontent.apps.123:redirect_uri_path
com.example.app is the reverse DNS notation of a domain under your control. The custom scheme must contain a period to be valid.
com.googleusercontent.apps.123 is the reverse DNS notation of the client ID.
redirect_uri_path is an optional path component, such as /oauth2redirect. Note that the path should begin with a single slash, which is different from regular HTTP URLs.

^从文档复制. 123是您的客户ID. com.googleusercontent.apps是固定的,不是可变的.在您的应用中将其设置为重定向uri可以确保Google将用户引导回您的应用,库将在其中处理获取访问令牌和用户个人资料等.您需要在manifest.xml中有一个意图过滤器(或Xamarin中的以下内容)以接收uri.

^ Copied from documentation. 123 is your client id. And com.googleusercontent.apps is fixed, not variable. Setting this as the redirect uri in your app will make sure that google directs user back to your app, where the library will handle getting the access token and user profile, etc. You need to have an intent filter in your manifest.xml (or the following in Xamarin) to receive the uri.

[IntentFilter(
    new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataSchemes = new[] { "com.googleusercontent.apps.123" },
    DataPath = "/oauth2redirect")]

它在Manifest.xml中是等效的:

Its equivalent in the Manifest.xml:

<activity android:label="ActivityCustomUrlSchemeInterceptor" android:launchMode="singleTop" android:noHistory="true" android:name="crc640d96480bfe206cdf.ActivityCustomUrlSchemeInterceptor">
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:path="/oauth2redirect" />
    <data android:scheme="com.googleusercontent.apps.123" />
  </intent-filter>
</activity>

这篇关于没有重定向uri的Android版Google登录如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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