public async Task <ActionResult <LogoutDTO> > LogoutAsync([FromServices] IInvalidatedTokenService invalidatedService) { if (authenticationOptions.IsUnsecured || !authenticationOptions.Logout.Enabled) { return(StatusCode(StatusCodes.Status404NotFound)); } var nonce = User.FindFirst(Nonce.Id).Value; var ticks = Convert.ToInt64(User.FindFirst(JwtRegisteredClaimNames.Exp).Value); var token = InvalidatedToken.FromUTCTicks(nonce, ticks); try { logger.LogInformation("Invalidating Token: {@Token}", token); await invalidatedService.Invalidate(token); } catch (Exception e) { logger.LogError("Failed to logout user. Error:{Error}", e.ToString()); } return(Ok(new LogoutDTO { LogoutURI = authenticationOptions.Logout.URI?.AbsoluteUri })); }
public BackgroundInvalidatedTokenSynchronizer( IInvalidatedTokenCache cache, IInvalidatedTokenService tokenInvalidatedService, ILogger <BackgroundInvalidatedTokenSynchronizer> logger) { this.cache = cache; this.tokenInvalidatedService = tokenInvalidatedService; this.logger = logger; }