Rak*_*ngh 5 oauth-2.0 react-native appauth react-native-android
我正在尝试使用 FormidableLab 的react-native-app-auth库在我的 react native android 应用程序中实现 Google OAuth 2 登录,如下所示:
googleLoginPressed = async () => {
const config = {
serviceConfiguration: {
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth', tokenEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
},
clientId: app_params.GOOGLE_CLIENT_ID, redirectUrl: 'https://<my_domain>/oauth/google',
scopes: ['openid', 'profile', 'email'], additionalParameters: { 'response-type': 'code' },
};
try {
const result = await authorize(config);
} catch (error) {
console.log(error);
}
}
Run Code Online (Sandbox Code Playgroud)
这会使用 Google 的登录页面调用 Web 视图,我可以成功验证自己的身份。然后 Google 正确地重定向到我的 oauth 回调端点,并code像它应该的那样在重定向 url 中填充 oauth 。在这一点上,我希望react-native-app-auth将控制权从 webview 恢复到应用程序。相反,Web 视图在重定向 url 页面上保持打开状态。
我在下面添加了必要的网站关联配置AndroidManifest.xml和下面的代码,MainActivity.java以检查是否从重定向 url 将控制权返回给应用程序:
@Override
public void onNewIntent(Intent intent) { // this is not getting hit
super.onNewIntent(intent);
Uri appLinkData = intent.getData();
if (appLinkData != null) {
bar = appLinkData.getPath();
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的
Universal links。所以网站关联一定能正常工作。如何将控制权从 oauth Web 视图返回到我的 react-native 代码?
| 归档时间: |
|
| 查看次数: |
1089 次 |
| 最近记录: |