首页 > 解决方案 > 如何在 Google Oauth2 上配置自定义 url

问题描述

我正在尝试在我的本机应用程序上使用谷歌设置登录。

我在Android上设置了我的自定义uri:

    <intent-filter android:label="filter_react_native">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.myapp" android:host='app'/>
    </intent-filter>

如果我使用 com.myapp://app 启动应用程序,一切都会完美运行。

https://developers.google.com/identity/protocols/OAuth2InstalledApp#creatingcred

根据这些文档,redirect_uri 可以是自定义的。“请注意,路径应以单斜杠开头,这与常规 HTTP URL 不同。” 重定向没有问题的唯一方法是:

Linking.openURL([
  'https://accounts.google.com/o/oauth2/auth',
  '?response_type=code',
  '&client_id=' + clientID,
  '&redirect_uri=com.myapp:/app',
  '&scope=https://www.googleapis.com/auth/plus.login',
  '+https://www.googleapis.com/auth/userinfo.email',
  '+https://www.googleapis.com/auth/userinfo.profile'
].join(''))

除非我输入密码并接受条款,否则我会收到以下错误:

The webpage at com.myapp:/app?code=XXXX could not be loaded because:
net:: ERROR_UNKNOWN_URL_SCHEME

我哪里错了?

标签: react-nativeoauth-2.0google-oauthcustom-url

解决方案


推荐阅读