在企业 AD 中的 Windows 10 上使用 ADAL for .NET 登录到 Azure AD

Sign in to Azure AD using ADAL for .NET on Windows 10 within a corporate AD

最近,我遇到了以下针对此环境的 ADAL for .NET 行为:Windows 10 + 企业活动目录。

...

authContext = new AuthenticationContext(authority);

...

var tokenResult = await authContext.AcquireTokenAsync(
    resourceId,
    clientId,
    redirectUri,
    new PlatformParameters(PromptBehavior.Auto, parentWindow));

使用 PromptBehavior.Auto 我无法使用正确的帐户登录,因为 ADAL 库不显示登录 window(在屏幕截图上),而是使用我的帐户m 当前登录到 Windows 10(这最终显然会导致访问被拒绝错误,因为我登录到 Windows 的帐户不在我正在连接的 Azure AD 中)。

有趣的是,同样的代码对于我正在 Windows 7.

的同事来说可以正常工作

那么,这里可能存在的问题是什么?

PromptBehavior.Auto 将尝试使用活动令牌,但如果刷新令牌为 invalid/expired 或需要凭据,则不会显示登录页面。您可能有一个会话需要出于某种原因重新进行身份验证,并且系统会提示您为缓存中的用户再次登录。如果您在 Win 10 设备上加入了域,它将自动使用该用户。

您应该可以点击 Use another account 按钮来登录其他用户。或者,您可以使用 PromptBehavior.Always 这将忽略缓存并允许您登录新用户。