Nik*_*lov 5 c# identityserver4
我在我的项目中使用 IdentityServer4 和 ASP.NET Identity。我的目标是添加分配动态令牌到期时间的逻辑。我正在关注有关ICustomTokenRequestValidator 的IdSrv4 文档中的此主题。
我的初始验证器非常基础。
public class TokenLifetimeValidator : ICustomTokenRequestValidator
{
public Task ValidateAsync(CustomTokenRequestValidationContext context)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
这是 IdSrv4 配置:
services.AddIdentityServer()
.AddAspNetIdentity<ApplicationUser>()
.AddInMemoryIdentityResources(new IdentityResource[] { new IdentityResources.OpenId(), new IdentityResources.Profile() })
.AddInMemoryApiResources(new ApiResource[] { new ApiResource("api", new[] { JwtClaimTypes.Name, JwtClaimTypes.Role }) })
.AddInMemoryClients(new Client[]
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api"
},
AllowAccessTokensViaBrowser = true,
RequireConsent = false,
RedirectUris = Configuration.GetSection("RedirectUris").Get<string[]>(),
PostLogoutRedirectUris = Configuration.GetSection("PostLogoutRedirectUris").Get<string[]>(),
AccessTokenLifetime = 60*60*24, // 24 Hours
IdentityTokenLifetime = 60*60*24 // 24 Hours
}
})
// Not working.
---> //.AddCustomTokenRequestValidator<TokenLifetimeValidator>()
.AddDeveloperSigningCredential();
// Not working.
---> services.AddTransient<ICustomTokenRequestValidator, TokenLifetimeValidator>();
Run Code Online (Sandbox Code Playgroud)
无论我如何注册自定义验证器,它都永远不会被执行。我使用 IdentityServer4 2.0.0、2.1.0、2.3.2、2.4.0 进行了测试。
我怎样才能让验证器被执行?
谢谢!
编辑:
登录由oidc-client.js及其执行userManager.signinRedirect。
this.userManager = new UserManager({
authority: environment.issuer,
client_id: 'client',
scope: 'openid profile api',
response_type: 'id_token token',
loadUserInfo: true,
automaticSilentRenew: true,
redirect_uri: environment.app + '/login-callback.html',
silent_redirect_uri: environment.app + '/silent-renew.html',
post_logout_redirect_uri: environment.app
});
Run Code Online (Sandbox Code Playgroud)
事实证明,为我的流程实现的适当接口是ICustomAuthorizeRequestValidator.
ICustomAuthorizeRequestValidatorICustomTokenRequestValidator感谢Vidmantas Blazevicius和d_f的指点。
| 归档时间: |
|
| 查看次数: |
4976 次 |
| 最近记录: |