我是 React Native 新手,我正在尝试使用 Azure AD B2C 和 react-native-app-auth 授权我的应用程序.
当系统浏览器正在启动并且我可以登录时,我正在努力解决的是使用正确的应用程序方案重定向回应用程序。
Android 上大多数基于 Azure 的文档
( like here 、 here 和 here )指示我使用签名和方案作为 AndroidManifest.xml
中的 Activity 这样应用程序就可以响应流程。
<activity
android:name="com.microsoft.identity.client.BrowserTabActivity">
<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="msauth"
android:host="Enter_the_Package_Name"
android:path="/Enter_the_Signature_Hash" />
</intent-filter>
</activity>
但是 react-native-app-auth
的 React Native 文档(如 here 和 here )说我需要设置 appAuthRedirectScheme
在 android/app/build.grandle
文件。
我不确定哪种方法合适,理论上这应该不难。但是,当我尝试任一方法时,我要么在成功登录后没有得到任何响应(即可能发生重定向,但应用程序没有监听),要么应用程序完全挂起。
关于如何使重定向发挥作用,有明确的指示吗?
更新
我通过 react-native-app-auth
阅读文档
The scheme is the beginning of your OAuth Redirect URL, up to the scheme separator (:) character. E.g. if your redirect uri is com.myapp://oauth, then the url scheme will is com.myapp. The scheme must be in lowercase.
这似乎与其他 Azure 文档的工作方式不同,其中方案是包名称。就我而言,我必须将方案更改为 msauth
.
manifestPlaceholders = [appAuthRedirectScheme: 'msauth']
这可行,但是这不会与其他应用程序冲突吗?最佳实践表明我应该使包名称唯一,并保持 RedirectUri 唯一。但如果方案设置为msauth
,这样不会和其他应用冲突吗?
最佳答案
手动更改 list 菜单中 Azure 自动生成的重定向 URI 很有帮助。
在 UI 上的 JSON list 中的 replyUrlsWithType
键下查找 Android 的重定向 URI。
从 msauth://package-name/signature-hash
更改为 package-name://msauth/signature-hash
。单击“保存”按钮保存文件。
在 build.gradle
文件中,您可以使用您的包名称。
android {
// ...
defaultConfig {
// ...
manifestPlaceholders = [
appAuthRedirectScheme: "package-name"
]
}
// ...
}
关于android - 使用 React Native 应用程序进行身份验证重定向 (Azure B2C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72744516/