且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-12-04 13:01:34

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