I am using the OpenIdConnect provider with Owin / Katana for authentication in my asp.net mvc application. OpenIdConnect Provides Active Directory user authentication. I wanted to do a simple authorization check after authenticating the user and redirecting the user to another view.
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)
{
identity.AddClaim(new Claim(CustomClaimTypes.PersonId, user.Name.ToString()));
}
else
{
}
return Task.FromResult(0);
}
}
});
How to redirect a user if he is not in my database.
source
share