Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro ao tentar gerar uma chave de token

Olá, consegui implementar o identity e o banco de dados está conectado, consigo introduzir novos cadastros porem a aplicação está rodando na depuração sem erro algum, mas nao consigo geraar um token, ao tentar gerar um otken recebo a mensagem no postman:

System.ArgumentOutOfRangeException: IDX10720: Unable to create KeyedHashAlgorithm for algorithm 'HS256', the key size must be greater than: '256' bits, key has '200' bits. (Parameter 'keyBytes') at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ValidateKeySize(Byte[] keyBytes, String algorithm, Int32 expectedNumberOfBytes) at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateKeyedHashAlgorithm(Byte[] keyBytes, String algorithm) at Microsoft.IdentityModel.Tokens.DisposableObjectPool1.Allocate() at Microsoft.IdentityModel.Tokens.SymmetricSignatureProvider.Sign(Byte[] input) at Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.CreateEncodedSignature(String input, SigningCredentials signingCredentials) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token) at UsuariosApi_Identity.Services.TokenService.GenerateToken(Usuario usuario) in C:\Users\ERICK\Documents\WORKSPACE\ESTUDOS\.NET\UsuariosApi-Identity\UsuariosApi-Identity\UsuariosApi-Identity\Services\TokenService.cs:line 40 at UsuariosApi_Identity.Services.UsuarioService.Login(LoginUsuarioDto dto) in C:\Users\ERICK\Documents\WORKSPACE\ESTUDOS\.NET\UsuariosApi-Identity\UsuariosApi-Identity\UsuariosApi-Identity\Services\UsuarioService.cs:line 53 at UsuariosApi_Identity.Controllers.UsuarioController.Login(LoginUsuarioDto dto) in C:\Users\ERICK\Documents\WORKSPACE\ESTUDOS\.NET\UsuariosApi-Identity\UsuariosApi-Identity\UsuariosApi-Identity\Controllers\UsuarioController.cs:line 30 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 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.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|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.g__Awaited|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.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

2 respostas
solução!

Achei uma solução, estava utilizando uma chave de token muito curta por exemplo:

SymmetricSecurityKey: "43443FDFDF34DF34343fdf344"

atualizei para:

"SymmetricSecurityKey": "43443FDFDF34DF34343fdf344SDFSDFSDFSDFSDF4545354345SDFGDFGDFGDFGdffgfdGDFGDGR%"

e funcionou !

Boa Erick!