在没有重定向uri的情况下,Android版的谷歌登录是如何工作的



Android上的Google登录库在不指定任何重定向uri的情况下工作。为什么会出现这种情况?用户登录后,谷歌将访问代码发送到哪个端点?它是如何将用户重定向回应用程序的?

谢谢。

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

一旦将用户重定向回应用程序,谷歌登录库就会处理获取令牌和用户信息的问题。

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将确保谷歌将用户引导回你的应用程序,库将在那里处理获取访问令牌和用户配置文件等。你需要在manifest.xml(或Xamarin中的以下内容(中有一个意向过滤器来接收uri。

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

它在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>

最新更新