【发布时间】:2017-05-04 10:18:46
【问题描述】:
我有很多应用程序,我正在将身份验证切换到 ADFS,我需要添加自定义数据,比如说成功登录后数据库中的一组角色。
场景解释:
每个应用程序在 DB 中都有自己的角色,
在发送授权请求后的用户身份验证期间,Application_AuthenticateRequest(object sender, EventArgs e) 将被调用,因此我可以像这样添加角色作为声明
((ClaimsIdentity)((ClaimsPrincipal)currentUser).Identity)
.AddClaim(new Claim(ClaimTypes.Role, "role1FromDataBase"));
HttpContext.Current.User = currentUser;
但是Application_AuthenticateRequest() 方法会为每个请求调用,我不想每次都从数据库中请求角色。
所以,我需要在某处添加这些角色,然后才能调用它们。当然,当我处理基于 API 角色的授权时,Sessions 和 Cookies 并不是最佳实践。
应用程序在 Windows server 2012 上具有控制器和 API 以及我的 ADFS
我的 OWIN 启动是
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata,
Notifications = new WsFederationAuthenticationNotifications()
{
RedirectToIdentityProvider = context =>
{
context.ProtocolMessage.Wreply = "https://localhost:44329/";
return Task.FromResult(0);
}
},
});
app.UseStageMarker(PipelineStage.Authenticate);
我能做什么?
【问题讨论】:
标签: c# asp.net ws-federation adfs3.0