aram87 / TasksApi

A simple API built in ASP.NET Core Web API 6, connecting SQL Server Express database with EF Core and using JWT-based authentication with refresh tokens
62 stars 35 forks source link

Error on Login with Postman #1

Open luisggarcia opened 1 year ago

luisggarcia commented 1 year ago

error when try to login with Postman error

"System.IdentityModel.Tokens.Jwt.JwtPayload.AddFirstPriorityClaims(String issuer, String audience, Nullable1 notBefore, Nullable1 expires, Nullable`1 issuedAt)"

System.ArgumentException: IDX12401: Expires: '18/09/2023 10:00:52 a. m.' must be after NotBefore: '18/09/2023 03:45:52 p. m.'. at System.IdentityModel.Tokens.Jwt.JwtPayload.AddFirstPriorityClaims(String issuer, String audience, Nullable1 notBefore, Nullable1 expires, Nullable1 issuedAt) at System.IdentityModel.Tokens.Jwt.JwtPayload..ctor(String issuer, String audience, IEnumerable1 claims, IDictionary2 claimsCollection, Nullable1 notBefore, Nullable1 expires, Nullable1 issuedAt) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateJwtSecurityTokenPrivate(String issuer, String audience, ClaimsIdentity subject, Nullable1 notBefore, Nullable1 expires, Nullable1 issuedAt, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, IDictionary2 claimCollection, String tokenType, IDictionary2 additionalHeaderClaims, IDictionary2 additionalInnerHeaderClaims) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateToken(SecurityTokenDescriptor tokenDescriptor) at TasksApi.Helpers.TokenHelper.GenerateAccessToken(Int32 userId) in C:\Users\8001138\Source\Repos\TasksApi\TasksApi\Helpers\TokenHelper.cs:line 33 at TasksApi.Services.TokenService.GenerateTokensAsync(Int32 userId) in C:\Users\8001138\Source\Repos\TasksApi\TasksApi\Services\TokenService.cs:line 21 at TasksApi.Services.UserService.LoginAsync(LoginRequest loginRequest) in C:\Users\8001138\Source\Repos\TasksApi\TasksApi\Services\UserService.cs:line 69 at TasksApi.Controllers.UsersController.Login(LoginRequest loginRequest) in C:\Users\8001138\Source\Repos\TasksApi\TasksApi\Controllers\UsersController.cs:line 35 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

HEADERS

Accept: / Connection: keep-alive Host: localhost:7217 User-Agent: PostmanRuntime/7.33.0 Accept-Encoding: gzip, deflate, br Content-Type: application/json Content-Length: 71 Postman-Token: 58ea1a67-6e38-4d7b-85de-a916f11bc305

luisggarcia commented 1 year ago

I found solution changing standard time tp UTC time. On "TokenHelper.cs" program line 30.

//Expires = DateTime.Now.AddMinutes(15), I changed to UTC Time Expires = DateTime.UtcNow.AddMinutes(15),