Exemplo n.º 1
0
        public async Task <ActionResult <LogoutDTO> > LogoutAsync([FromServices] ITokenBlacklistService blacklistService)
        {
            if (authenticationOptions.IsUnsecured)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            var nonce = User.FindFirst(Nonce.Id).Value;
            var ticks = Convert.ToInt64(User.FindFirst(JwtRegisteredClaimNames.Exp).Value);
            var token = BlacklistedToken.FromUTCTicks(nonce, ticks);

            try
            {
                logger.LogInformation("Blacklisting Token: {@Token}", token);
                await blacklistService.Blacklist(token);
            }
            catch (Exception e)
            {
                logger.LogError("Failed to logout user. Error:{Error}", e.ToString());
            }

            return(Ok(new LogoutDTO {
                LogoutURI = authenticationOptions.LogoutURI?.AbsoluteUri
            }));
        }
 public BackgroundTokenBlacklistSynchronizer(
     ITokenBlacklistCache cache,
     ITokenBlacklistService tokenBlacklistService,
     ILogger <BackgroundTokenBlacklistSynchronizer> logger)
 {
     this.cache = cache;
     this.tokenBlacklistService = tokenBlacklistService;
     this.logger = logger;
 }