首页 > 解决方案 > 使用 AcquireTokenInteractive 时出现 MsalServiceException。AADSTS80014:验证请求在超过最大经过时间后响应

问题描述

我有一个 Xamarin Forms iOS 应用程序,它使用 MSAL (Microsoft.Identity.Client) 来获取访问令牌。

var app = PublicClientApplicationBuilder.Create(AppSettings.ClientId)
          .WithTenantId(AppSettings.TenantId)
          .WithIosKeychainSecurityGroup("com.microsoft.adalcache")
          .WithRedirectUri($"msal{AppSettings.ClientId}://auth")
          .Build();

var authResult = await this.app.AcquireTokenInteractive(scopes)
                  .WithParentActivityOrWindow(App.CurrentActivityOrWindow)
                  .ExecuteAsync();

此代码在 Android 上运行良好,但在 iOS 上,输入用户名和密码后,MsalUiRequiredException会抛出 an 。我在我的 Microsoft Work 或 School 帐户上启用了两个因素,并且似乎在登录的第二部分之前引发了异常。

AADSTS80014: Validation request responded after maximum elapsed time exceeded.

异常详细信息似乎表明发生了超时,因此我尝试使用HttpClientFactory增加超时的自定义,但仍然在同一位置抛出异常。

我的OpenUrl覆盖AppDelegate不会被调用。

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
    // Never get here
    AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url);
    return base.OpenUrl(app, url, options);
}

我已经在我的Info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>{bundle Id}</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>msal{clientId}</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
    </dict>
</array>

并启用钥匙串访问Entitlements.plist

<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
    </array>
 </dict>

我很确定 Azure 方面的配置正确,因为它在 Android 上运行。我需要在 iOS 上做其他事情吗?

标签: xamarinxamarin.formsxamarin.iosmsalazure-authentication

解决方案


此答案不太可能适用于其他任何人,但问题是由于我们的 AD Sync 服务器脱机造成的。

现有的访问令牌正在工作,但我无法获得任何新的。


推荐阅读