没有重定向uri的Android登录如何工作?

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

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

谢谢。

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

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

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

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。

[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>
© www.soinside.com 2019 - 2024. All rights reserved.