React 本机应用程序身份验证(android)显示两个具有相同重定向方案的应用程序?

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

Click here to view screenshot here

我正在将React Native应用程序身份验证与Azure Active Directory一起使用,并且在重定向回应用程序后在Android中使用,会显示两个应用程序(如上面的屏幕截图所示),如果我选择正确的应用程序,则应用程序将按预期工作,但如果我选择另一个是应用程序崩溃。我怎样才能解决这个问题并只显示一个应用程序!

const config = {
  issuer: 'https://login.microsoftonline.com/your-tenant-id',
  clientId: 'your-client-id',
  redirectUrl: 'urn:ietf:wg:oauth:2.0:oob',
  scopes: [], // ignored by Azure AD
  additionalParameters: {
    resource: 'your-resource'
  }
};

// Log in to get an authentication token
const authState = await authorize(config);

// Refresh token
const refreshedState = await refresh(config, {
  refreshToken: authState.refreshToken,
});
android react-native oauth url-scheme
2个回答
1
投票

尽量不要将 "scheme" 选项放入 app.json 并使用这样的redirectUrl。

<your.package.identifier>://oauthredirect

根据此AppAuth OAuthRedirect,AppAuth 使用 android.package 标识符作为方案。例如,如果您的 package.identifier 是 "your.company.app",请使用这样的重定向 URL:

your.company.app://oauthredirect
。它对我有用。


0
投票

问题可能是根据文档添加的配置加倍:https://github.com/FormidableLabs/react-native-app-auth#android-setup

一种方法是在 android/app/build.gradle 文件中添加链接:

android {
  defaultConfig {
    manifestPlaceholders = [
      appAuthRedirectScheme: 'io.identityserver.demo'
    ]
  }
}

另一种方法是在 AndroidManifest 中添加配置:

<activity
    android:name="net.openid.appauth.RedirectUriReceiverActivity"
    tools:node="replace">
    <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:scheme="com.example.app"/>
    </intent-filter>
</activity>

如果您同时添加,它将被注册两次,因此登录后会出现选择应用程序的弹出窗口。

© www.soinside.com 2019 - 2024. All rights reserved.