react-native - 如何在 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
我哪里错了?
解决方案
推荐阅读
- testing - 在没有 UI 交互的情况下设置值。赛普拉斯应用程序操作
- php - 为什么 DOMDocument 会弄乱 unicode 不间断空格
- java - 即使我使用的是 Locale.US,点也会返回 MisMatch 异常
- r - 如何根据具有条件的两个列删除重复项?
- windows - 是否存在 ReadProcessMemory 失败的情况?
- ethereum - 检测 MetaMask 注销(以太坊)
- c - 生成数独谜题
- python - 如何将我的简单游戏从 .py 文件转换为可执行文件?
- angular - 如何在 Angular 中模拟 AWS Amplify 库?
- javascript - React / Redux 身份验证路由未重定向