带有 Capacitor 和 React 的 Auth0 在身份验证后不会重定向到应用程序

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

我一直在遵循本指南为在 Android 设备上运行的 Capacitor React 应用程序设置 Auth0 集成 (https://auth0.com/docs/quickstart/native/ionic-react/interactive)。

我陷入了必须“处理原始回调”的部分。我根据指南的说明设置的

appUrlOpen
侦听器的代码似乎没有运行。我在监听器回调中放入的警报似乎没有出现。我使用了 uri 示例,他们说在前面的步骤中设置 Auth0 包装器时,我应该使用
"YOUR_PACKAGE_ID://{yourDomain}/capacitor/YOUR_PACKAGE_ID/callback"
作为重定向_uri。我还确保redirect_url 是允许的回调url 的一部分。我还使用他们在此处提供的指南设置了深度链接(https://developer.android.com/training/app-links/deep-linking)。然而,当涉及到我的
AndroidManifest.xml
上的数据的android主机时,我不知道该提供什么。所以现在,它是我仪表板上 auth0 应用程序中的域。

当我在模拟器上运行我的应用程序时,我能够成功进行身份验证(我能够在 auth0 日志中看到成功登录),但它只是停留在通用登录屏幕上,不执行任何操作,甚至不点击appUrlOpen 侦听器。我还想知道应该使用什么作为有效的回调 URI。

完成所有这些步骤后,如何正确返回应用程序?我是否错过了某些步骤?我的深层链接不起作用的原因是什么?

我尝试将应用程序切换到我的组织使用的其他 auth0 应用程序,并且我尝试相应地更改回调 uri 和其他变量。我还在这里检查了电容器自己的深层链接指南(https://capacitorjs.com/docs/guides/deep-links),这促使我制作 SHA-256 密钥存储并设置我的网站以进行深层链接。我不太知道这如何适用于我的应用程序。

android reactjs auth0 capacitor
1个回答
0
投票

意图过滤器中的数据标签应包含“custom_url_scheme”

<data android:scheme="@string/custom_url_scheme" />

AndroidManifest.xml 应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.auth0.samples">

    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">

        <activity
            android:exported="true"
 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:name="com.auth0.samples.MainActivity" android:label="@string/title_activity_main" android:theme="@style/AppTheme.NoActionBarLaunch" android:launchMode="singleTask">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <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="@string/custom_url_scheme" />
            </intent-filter>

        </activity>

        <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

以下是您应该重新检查的一些事项:

  1. 添加回调和注销URL

  2. 添加以下允许来源 (CORS):

    capacitor://localhost, http://localhost

  3. 查看示例代码:https://github.com/auth0-samples/auth0-ionic-samples/tree/main/react。检查您的申请中是否存在不一致之处。

  4. 如果没有任何效果,您可以随时下载一个工作示例应用程序来分析文件或开始在其基础上构建:https://auth0.com/docs/quickstart/native/ionic-react/interactive

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