android - 使用 React Native 应用程序进行身份验证重定向 (Azure B2C)

标签 android azure react-native redirect

我是 React Native 新手,我正在尝试使用 Azure AD B2C 和 react-native-app-auth 授权我的应用程序.

当系统浏览器正在启动并且我可以登录时,我正在努力解决的是使用正确的应用程序方案重定向回应用程序。

Android 上大多数基于 Azure 的文档 ( like hereherehere )指示我使用签名和方案作为 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 文档(如 herehere )说我需要设置 appAuthRedirectSchemeandroid/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 ,这样不会和其他应用冲突吗?

enter image description here

最佳答案

手动更改 list 菜单中 Azure 自动生成的重定向 URI 很有帮助。

在 UI 上的 JSON list 中的 replyUrlsWithType 键下查找 Android 的重定向 URI。 Azure AD Application Manifest

msauth://package-name/signature-hash 更改为 package-name://msauth/signature-hash。单击“保存”按钮保存文件。

Azure AD Application Manifestbuild.gradle 文件中,您可以使用您的包名称。

android {
    // ...
    defaultConfig {
        // ... 

        manifestPlaceholders = [
          appAuthRedirectScheme: "package-name"
        ]
    }
    // ...
}

关于android - 使用 React Native 应用程序进行身份验证重定向 (Azure B2C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72744516/

相关文章:

javascript - Azure 移动服务 : Get Server DateTime and compare it

azure - 从 Internet 访问 Azure Service Fabric 应用程序

azure - 我可以使用 Azure 交互模式进行 azure-cli-ml 扩展吗?

javascript - 类型错误 : undefined is not an object (evaluating 'data.filter' ) - React Native

android - 如何复制 Google Cardboard Photosphere App

android - 将Android Studio更新到版本0.4.0。什么都行不通!哪些修复?

javascript - React Native Fade In Animation 不流畅

react-native - react native : How to disable scrolling in ListView?

android - 为什么 android 在显示 png 文件时会丢失图像质量?

android - 无需重新启动即可启动服务计划?