Exemple #1
0
        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
            }));
        }
Exemple #2
0
 public void Invalidate(InvalidatedToken token)
 {
     sync.EnterWriteLock();
     try
     {
         invalidated.Add(token.IdNonce);
     }
     finally
     {
         sync.ExitWriteLock();
     }
 }
Exemple #3
0
        public async Task Invalidate(InvalidatedToken token)
        {
            invalidatedCache.Invalidate(token);
            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                await cn.ExecuteAsync(
                    queryInvalidated,
                    new { idNonce = token.IdNonce, exp = token.Expires },
                    commandType : CommandType.StoredProcedure,
                    commandTimeout : opts.DefaultTimeout
                    );
            }
        }