k29*_*k29 7 azure owin azure-active-directory
使用 OWIN 和 OpenId 使用 Azure Active Directory 对我的基本 Web 应用程序的用户进行身份验证,如 Microsoft 示例项目中的 Readme.md 中所述:https : //github.com/Azure-Samples/active-directory-dotnet-webapp-打开idconnect
以下项目在我的 web.config 中:
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44320/" />
Startup.Auth 如下:
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = "https://localhost:44320/Home/About",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我花了很多时间正确地弄清楚如何让它发挥作用。即使三年前我们只是没有打扰。互联网上似乎有很多人遇到这个问题,我想确保每个人都能找到这个问题的答案。
以下解决方案适用于标准 Azure AD 出现的问题。如果您使用组织帐户登录,它也适用于 Azure AD B2C。(请注意,此解决方案不涵盖新的 b2clogin URI 和用户流技术,因为在我提出问题时它还不存在)
当被问到这个问题时,Azure 中似乎存在某种错误。解决方法如下:用作注销后重定向的 URI 必须在回复 URL 和前端通道注销 URL 中指定。通常,前通道注销是 IDP 发送到您的应用程序的静默请求,以允许您运行逻辑来清除 cookie,但不会导致重定向。在实施此操作之前,您应该检查 Microsoft 是否已修复该问题。
请小心不要在 URI 末尾意外添加尾部斜杠。尝试使它们在此处和您的客户端应用程序中保持完全相同。
形式的权威https://login.microsoftonline.com/<org-name>.onmicrosoft.com/V2.0是行不通的。https://login.microsoftonline.com/<tenant-id>/V2.0对于标准的 Azure AD,我必须将权限更改为特定租户的形式 ,或者https://login.microsoftonline.com/common/V2.0我认为在某些场景中也会使用该形式。对于 B2C AD 租户,它仅适用于common上述端点。
旁注 1:对于端点,common您必须ValidateIssuer在令牌验证参数中将其设置为 false,否则您将收到异常。正确进行验证超出了这个问题的范围。
旁注 2:在 Google 上搜索此问题时,您可能会遇到一些针对 Identity Server 身份验证问题的解决方案。解决方案和规范建议您将 id_token_hint 添加到注销请求中。这对于我让重定向适用于 Azure AD 来说既不充分也没有必要。
| 归档时间: |
|
| 查看次数: |
1976 次 |
| 最近记录: |