【发布时间】:2020-09-20 19:28:27
【问题描述】:
我正在将 SSO 引入旧版应用程序。我需要管理的一项现有功能是检查用户是否可以在登录后访问应用程序。以前,如果他们登录,他们的帐户将根据 db 表进行检查,他们将被注销系统一条消息说,如果他们的访问被拒绝,他们必须联系支持人员。如果可能,我正在寻找新的 SSO 登录时相同的功能。因此,下面的代码的 sn-p。任何建议将不胜感激。
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = OnAuthenticationFailed,
SecurityTokenValidated = (context) =>
{
ClaimsIdentity identity = context.AuthenticationTicket.Identity;
// check the database if the user is locked from accessing the system
var userEmail = identity.FindFirst("preferred_username").Value;
var currentUser = UsersTable.Where(user => user.Email == userEmail);
if (currentUser != null )
{
if (currentUser.AccessLocked)
{
at this point I need to prevent the user for using the system. My preferred option would be to
Force logout, and redirect back to the login page, with a message saying that user access is locked
The other option
// 2 - Add Roles on each of the controller (IsActive) and add a Claim Role Type for a user who does have access
identity.AddClaim(new Claim(ClaimTypes.Role, "IsActive"));
I have tried this, but I get stuck in a authorisation loop when the user doesn not have the Role
}
}
}
}
【问题讨论】:
标签: asp.net-mvc azure-active-directory single-sign-on openid-connect