是否可以覆盖自定义OAuthAuthorizationServerProvider上特定票证的默认AccesstokenExpireTimeSpan?所有其他票证的默认到期时间为15分钟.
public public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { ... var ticket = new AuthenticationTicket(identity,properties); if (condition) { ticket.Properties.IssuedUtc = DateTime.UtcNow; ticket.Properties.ExpiresUtc = DateTime.UtcNow.AddDays(14); } context.Validated(ticket); }
条件== true的生成令牌具有默认的到期时间(15分钟).我不想更改context.Options.AccesstokenExpireTimeSpan,因为它会影响所有令牌,这不是主意.
解决方法
您必须在TokenEndPoint方法中设置到期时间而不是GrantResourceOwnerCredentials方法:
public override Task TokenEndpoint(OAuthTokenEndpointContext context) { ... if (condition) { context.Properties.ExpiresUtc = DateTime.UtcNow.AddDays(14); } ... }
我希望它有所帮助.
编辑
正如Michael在其response中针对类似问题所指出的,如果每个client_id都有不同的AccesstokenExpireTimeSpan,则可以在验证客户端身份验证时使用客户端覆盖上下文选项中的默认配置的AccesstokenExpireTimeSpan:
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) { ... context.Options.AccesstokenExpireTimeSpan = TimeSpan.FromMinutes(client.AccesstokenExpireTime); ... }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。