MSAL Android:获取令牌时缺少类型为 {0} 的必需令牌

And*_*Dev 5 android azure azure-ad-b2c azure-ad-msal

我正在将MSAL 2.2.1集成到 Android 应用程序中。

  1. 我已在 Azure b2c 门户中注册了该应用程序。
  2. 生成签名并将其添加到 Azure b2c 门户。
  3. 尝试获取令牌时获得登录页面。
  4. 成功登录后,MSAL 重定向到我们的应用程序。但不是 onSuccess 而是 onError 并带有以下堆栈跟踪。

onError:缺少类型所需的令牌:{0}

2021-10-05 03:16:21.310 9573-9573/com.test.msal W/System.err: com.microsoft.identity.client.exception.MsalClientException: Missing required tokens of type: {0}
2021-10-05 03:16:21.310 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter.msalExceptionFromBaseException(MsalExceptionAdapter.java:51)
2021-10-05 03:16:21.310 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.client.PublicClientApplication$18.onError(PublicClientApplication.java:1903)
2021-10-05 03:16:21.310 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.client.PublicClientApplication$18.onError(PublicClientApplication.java:1894)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher.commandCallbackOnError(CommandDispatcher.java:447)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher.access$800(CommandDispatcher.java:82)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher$3.run(CommandDispatcher.java:429)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at android.os.Handler.handleCallback(Handler.java:883)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:100)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at android.os.Looper.loop(Looper.java:214)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7697)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err: Caused by: com.microsoft.identity.common.exception.ClientException: Missing required tokens of type: {0}
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy.validateTokensAreInResponse(MicrosoftStsOAuth2Strategy.java:638)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy.validateTokenResponse(MicrosoftStsOAuth2Strategy.java:577)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy.validateTokenResponse(MicrosoftStsOAuth2Strategy.java:87)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy.validateTokenResponse(OAuth2Strategy.java:174)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy.requestToken(OAuth2Strategy.java:166)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.BaseController.performTokenRequest(BaseController.java:294)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.LocalMSALController.acquireToken(LocalMSALController.java:170)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.commands.InteractiveTokenCommand.execute(InteractiveTokenCommand.java:67)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.commands.InteractiveTokenCommand.execute(InteractiveTokenCommand.java:39)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher.executeCommand(CommandDispatcher.java:381)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher.access$000(CommandDispatcher.java:82)
2021-10-05 03:16:21.311 9573-9573/com.test.msal W/System.err:     at com.microsoft.identity.common.internal.controllers.CommandDispatcher$4.run(CommandDispatcher.java:584)
Run Code Online (Sandbox Code Playgroud)

我的请求代码如下所示:

application.acquireToken(requireActivity(),arrayOf("openid", "offline_access"),object : AuthenticationCallback {
Run Code Online (Sandbox Code Playgroud)

我已在 Azure b2c 门户中授予这些权限。

但仍然无法获取token。有人可以帮忙解决这个问题吗?提前致谢。

小智 7

我通过使用我的 client-id 作为 Scope 类型解决了这个问题:

public static List<String> getScopes() {
    return Arrays.asList(
            "your-client-id-here");
}
Run Code Online (Sandbox Code Playgroud)


小智 1

这是由于传递了无效的作用域类型或省略了所需的作用域值。就我而言,身份验证响应包含 and id_tokenrefresh_token但不包含access_token.

库提供的错误消息没有帮助,我在这里提交了一个问题: https: //github.com/AzureAD/microsoft-authentication-library-common-for-android/issues/1674