I am using OpenIddict to validate a token . Yesterday, when I call userManager.FindByNameAsync(request.Username) , I get a User with roles.
Today I get a user with the Roles property count = 0.
I tried loading roles using await userManager.GetRolesAsync(user); , and I get an array with a score of 3. This means that the user has roles.
I do not know what has changed, but how can I load a user using the FindByNameAsync function?
Full code:
[HttpPost("token"), Produces("application/json")] public async Task<IActionResult> Exchange(OpenIdConnectRequest request) { Debug.Assert(request.IsTokenRequest(), "The OpenIddict binder for ASP.NET Core MVC is not registered. " + "Make sure services.AddOpenIddict().AddMvcBinders() is correctly called."); if (request.IsPasswordGrantType()) { var user = await userManager.FindByNameAsync(request.Username); //roles count is 0 if (user == null) { return BadRequest(new OpenIdConnectResponse { Error = OpenIdConnectConstants.Errors.InvalidGrant, ErrorDescription = "The email/password couple is invalid." }); } var roles = await userManager.GetRolesAsync(user); //roles count is 3
source share