gpt4 book ai didi

asp.net-mvc - MVC5 OWIN ws-federation AuthenticationManager.GetExternalLoginInfoAsync() 返回 null

转载 作者:行者123 更新时间:2023-12-03 17:48:28 27 4
gpt4 key购买 nike

我正在尝试在 Visual Studio 2013 的新 MVC 5 项目中设置集成的 OWIN WS-Federation (ADFS) 身份验证。 Startup.Auth 中的 WsFederation 配置如下:

app.UseWsFederationAuthentication(wtrealm: "MyRealm",
metadataAddress: "https://myADFSInstanceHost/FederationMetadata/2007-06/FederationMetadata.xml");

登录页面上的联合按钮工作正常。 ADFS登录页面是可以实现的,我可以在那里登录。
所需的 cookie 似乎已正确设置。至少有传递 .AspNet.ExternalCookie cookie。
但是当执行对 mvc 应用程序的回调时,在 ExternalLoginCallback Controller 中 AuthenticationManager.GetExternalLoginInfoAsync() 总是返回 null。

最佳答案

我知道这是一个非常古老的帖子,但我已经在这个问题上工作了一个星期,这是我发现的唯一提供任何帮助的资源。

对原始帖子的评论正是我所需要的。为了GetExternalLoginInfo工作,类型为 NameIdentifier 的声明必须在场。我能够在 Startup.Auth.cs 中模拟其中之一使用以下代码:

app.UserWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm, //defined earlier
MetadataAddress = adfsMetadata, //also defined earlier

Notifications = new WsFederationAuthenticationNotifications()
{
SecurityTokenValidated = notification =>
{
ClaimsIdentity identity = notification.AuthenticationTicket.Identity;

//loop through all the claims returned (this should return everything set up in ADFS)
foreach (var claim in notification.AuthenticationTicket.Identity.Claims)
{
if (claim.Type == ClaimTypes.Upn) //or whatever claim type you want to use as your name identifier
{
//This line will add a duplicate claim, giving it the specified type. This NEEDS TO BE `NameIdentifier`
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, claim.Value));
}
}
return Task.FromResult(0);
}
}
});

关于asp.net-mvc - MVC5 OWIN ws-federation AuthenticationManager.GetExternalLoginInfoAsync() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com