diff --git a/src/Api/Middlewares/ExceptionMiddleware.cs b/src/Api/Middlewares/ExceptionMiddleware.cs index 194d73ab..cb6eb9e0 100644 --- a/src/Api/Middlewares/ExceptionMiddleware.cs +++ b/src/Api/Middlewares/ExceptionMiddleware.cs @@ -94,7 +94,7 @@ private async void HandleLimitExceededException(HttpContext context, Exception e private async void HandleAuthenticationException(HttpContext context, Exception ex) { - context.Response.StatusCode = StatusCodes.Status401Unauthorized; + context.Response.StatusCode = StatusCodes.Status400BadRequest; await WriteExceptionMessageAsync(context, ex); } diff --git a/src/Api/appsettings.Development.json b/src/Api/appsettings.Development.json index 535b16ec..41b82277 100644 --- a/src/Api/appsettings.Development.json +++ b/src/Api/appsettings.Development.json @@ -6,7 +6,7 @@ "JweSettings": { "SigningKeyId": "4bd28be8eac5414fb01c5cbe343b50144bd28be8eac5414fb01c5cbe343b50144bd28be8eac5414fb01c5cbe343b50144bd28be8eac5414fb01c5cbe343b50144bd28be8eac5414fb01c5cbe343b5014", "EncryptionKeyId": "4bd28be8eac5414fb01c5cbe343b5014", - "TokenLifetime": "00:00:05", + "TokenLifetime": "00:20:00", "RefreshTokenLifetimeInDays": 3 }, "Seed": true, diff --git a/src/Infrastructure/Identity/IdentityService.cs b/src/Infrastructure/Identity/IdentityService.cs index d1b36fac..58b7cf6e 100644 --- a/src/Infrastructure/Identity/IdentityService.cs +++ b/src/Infrastructure/Identity/IdentityService.cs @@ -119,17 +119,6 @@ public async Task RefreshTokenAsync(string token, string r { throw new AuthenticationException("Invalid token."); } - - var expiryDateUnix = - long.Parse(validatedToken.Claims.Single(x => x.Type.Equals(JwtRegisteredClaimNames.Exp)).Value); - - var expiryDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) - .AddSeconds(expiryDateUnix); - - if (expiryDateTimeUtc > DateTime.UtcNow) - { - throw new AuthenticationException("This token has not expired yet."); - } var jti = validatedToken.Claims.Single(x => x.Type.Equals(JwtRegisteredClaimNames.Jti)).Value; var storedRefreshToken = await _context.RefreshTokens.SingleOrDefaultAsync(x => x.Token.Equals(Guid.Parse(refreshToken)));