android 错误-意向筛选器:缺少BrowserTabActivity,使用AzureAD MSAL Lilbary时

sycxhyv7  于 2022-12-02  发布在  Android
关注(0)|答案(3)|浏览(141)

将AzureAD SSO集成到我的Android应用程序。我已经在Azure门户上注册了一个应用程序,并获得了auth_config.json文件。按照文档中提到的步骤实现了示例代码。但出现以下错误。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.poras.testapp/com.poras.testapp.MainActivity}: java.lang.IllegalStateException: Intent filter for: BrowserTabActivity is missing.  Please refer to the MSAL readme.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
     Caused by: java.lang.IllegalStateException: Intent filter for: BrowserTabActivity is missing.  Please refer to the MSAL readme.
        at com.microsoft.identity.client.PublicClientApplication.checkIntentFilterAddedToAppManifest(PublicClientApplication.java:1263)

下面是我的应用程序的AndroidManifest.xmlauto.config.json

<!--Intent filter to capture System Browser calling back to our app after Sign In-->
        <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" />

                <!--Add in your scheme/host from registered redirect URI-->
                <data android:scheme="msauth"
                    android:host= "com.poras.xxxxxxx"
                    android:path= "/vhhxxxxxxxxxxxxxxpqm0=" />
            </intent-filter>
        </activity>

auto_config.json

{
  "client_id" : "dxxxxxxxxxxxxxxxx3",
  "authorization_user_agent" : "DEFAULT",
  "redirect_uri" : "msauth://com.poras.xxxxxx/vhhxxxxxxxxxxxxxpmq0%3D",
  "authorities" : [
    {
      "type": "AAD",
      "audience": {
        "type": "AzureADandPersonalMicrosoftAccount",
        "tenant_id": "common"
      }
    }
  ]
}

我不知道我错过了什么。

m3eecexj

m3eecexj1#

如果清单中没有该代码段,则会出现此错误。
因此,请确保它与 Microsoft 站点所述完全一致,并将您的配置详细信息放在正确的位置。请确保您在manifest标记内的软件包属性中具有准确的软件包名称- like,以及提供给您的准确的签名哈希。我建议您从 *Microsoft门户 *(即https://ms.portal.azure.com/?feature.broker=true#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview)复制代码段。单击 * 应用注册 * 后选择您的应用。从 Android 下 * 管理 * 部分的 * 身份验证 * 链接;点击 Quickstart 获取为您的应用个性化的确切代码。(这将包含您的软件包名称(如果输入正确)和正确的签名哈希。)
同样,如果需要,可将代码插入到清单中:

<!--Intent filter to capture System Browser or Authenticator calling back to our app after sign-in-->
<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>

(code摘录自:(第10页)

qmb5sa22

qmb5sa222#

对我来说,这是因为我忽略了对URI的应用签名进行编码。因此res/raw/confing.json应该是:

"redirect_uri": "msauth://<yourpackagename>/<base64urlencodedsignature>"

但是AndroidManifest.xml应该是:

<activity android:name="com.microsoft.identity.client.BrowserTabActivity"
            android:exported="true">
            <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:host="<yourpackagename>"
                    android:path="/<signature>"
                    android:scheme="msauth" />
            </intent-filter>
        </activity>
xxhby3vn

xxhby3vn3#

另外,请注意哈希末尾的=。在Azure Portal中的重定向URI中将其替换为%3D

相关问题