1
I have the following problem:
Within the method GrantResourceOwnerCredentials
in class OAuthProvider : OAuthAuthorizationServerProvider
i am filling in custom properties to be returned with the Token. However, the object of the associated class UserProfile
always comes null after I use the FindAsync
, as shown in the row below:
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
I can include via Ager loading the associated object as follows:
await userManager.Users.Include("UserProfile").SingleOrDefaultAsync(u => u.UserName == context.UserName);
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
Only I think it is not correct, because I check the username in the bank before checking if it is correct (because of the password).
I wanted to carry this object after using the FindAsync
, but I don’t know how.
How can I do it using the user
?
There’s nothing wrong with the
Include
. I don’t understand your question. You want to check before if the user exists to load your information?– Leonel Sanches da Silva
So I check if it is correct within the context
if(context.UserName == null)
{
context.SetError("invalid_grant", "UserName field is required.");
return;
}
– Luiz Gustavo Maia
But what’s wrong with using the line with the
.SingleOrDefault
straightforward?– Leonel Sanches da Silva
Well, I thought it wasn’t good practice.
– Luiz Gustavo Maia
No, there is no problem. Just do the checks without unnecessarily exposing the data. Otherwise everything is in order.
– Leonel Sanches da Silva
Okay, I get it. Thank you!
– Luiz Gustavo Maia
You want me to answer, just so we can close the question?
– Leonel Sanches da Silva