【发布时间】:2015-09-09 20:00:56
【问题描述】:
我在我的 asp.net mvc 应用程序中使用 OpenIdConnect 提供程序和 Owin/Katana 进行身份验证。 OpenIdConnect 提供针对 Active Directory 对用户进行身份验证。一旦用户通过身份验证并将用户重定向到另一个视图,我想进行简单的授权检查。
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
{
Authority = "url",
Scope="scopes",
ResponseType = "response",
ClientId = "clientid",
SignInAsAuthenticationType = "Cookies",
Notifications = new OpenIdConnectAuthenticationNotifications()
{
SecurityTokenValidated = (context) =>
{
var identity = context.AuthenticationTicket.Identity;
var emailClaim = identity.Claims.Where(r => r.Type == ClaimTypes.Email).FirstOrDefault();
var user = dbContext.Users.Where(u=>u.Email==emailClaim.Value);
if (user != null)
{
//add user information to claims.
identity.AddClaim(new Claim(CustomClaimTypes.PersonId, user.Name.ToString()));
}
else
{
//redirect to a page
}
return Task.FromResult(0);
}
}
});
如果用户不在我的数据库中,我如何重定向用户。
【问题讨论】:
-
我终于能够使用自定义 Authorize 属性来实现这一点。
-
能否请您更详细地回答您自己的问题,并将其标记为答案?
-
当然,刚刚发布了我的答案@pashute。谢谢
标签: c# asp.net-mvc-5 owin openid-connect identityserver3