我正在将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,
});
尽量不要将 "scheme" 选项放入 app.json 并使用这样的redirectUrl。
<your.package.identifier>://oauthredirect
根据此AppAuth OAuthRedirect,AppAuth 使用 android.package 标识符作为方案。例如,如果您的 package.identifier 是 "your.company.app",请使用这样的重定向 URL:
your.company.app://oauthredirect
。它对我有用。
问题可能是根据文档添加的配置加倍: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>
如果您同时添加,它将被注册两次,因此登录后会出现选择应用程序的弹出窗口。