使用 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。我的 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 上还有什么我需要做的吗?

解决方法

这个答案不太可能适用于其他任何人,但问题是由我们的 AD Sync 服务器离线引起的。

现有的访问令牌有效,但我无法获得任何新令牌。