我正在使用此库https://github.com/openiddict/openiddict-core并实现了oAuth令牌流程。
// Register the OpenIddict services.
// Note: use the generic overload if you need
// to replace the default OpenIddict entities.
services.AddOpenIddict(options =>
{
// Register the Entity Framework stores.
options.AddEntityFrameworkCoreStores<ApplicationDbContext>();
// Register the ASP.NET Core MVC binder used by OpenIddict.
// Note: if you don't call this method, you won't be able to
// bind OpenIdConnectRequest or OpenIdConnectResponse parameters.
options.AddMvcBinders();
// Enable the token endpoint (required to use the password flow).
options.EnableTokenEndpoint("/connect/token");
// Allow client applications to use the grant_type=password flow.
options.AllowPasswordFlow();
// During development, you can disable the HTTPS requirement.
options.DisableHttpsRequirement();
});
大部分都是有效的。我还将RoleManager与它一起包括在内,并且使用以下函数将角色存储在令牌中:
var principal = await _signInManager.CreateUserPrincipalAsync(user);
foreach (var claim in principal.Claims.Where(c => c.Type == OpenIdConnectConstants.Claims.Role))
{
claim.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken, OpenIdConnectConstants.Destinations.IdentityToken);
}
到目前为止一切都已完成。之后管理员用户去修改角色以使他Supervisor
等。在角色更改的这一点上,我想让以前的令牌无效。这是否可以在图书馆中使用,因为目前他能够使用具有“女仆”角色且不正确的旧令牌,因为有人刚刚将他的角色改为“主管”。在这种情况下,我希望当客户端发送旧令牌时,它不应被视为有效,应该被发送回登录页面。
如何在OpenIDDict
库中处理此问题?