SiberianGuy
SiberianGuy

Reputation: 25312

Retrieve identity user with all navigation properties

I'm working with authentication in ASP.NET Web Api Core and at some point I process user data:

var user = await _userManager.GetUserAsync(HttpContext.User);
...
var userLogins = await _userManager.GetLoginsAsync(user);
...
var userClaims = await _userManager.GetClaimsAsync(user);
...

The problem is GetUserAsync does not load navigation properties, so I have to load them manually afterwards. Is there where a way to fix it without retrieving User object directly via DataContext?

Upvotes: 1

Views: 141

Answers (2)

SiberianGuy
SiberianGuy

Reputation: 25312

I ended up creating a filter that queries User with all the navigation properties included and stores it to HttpContext.Items (per query collection).

Upvotes: 1

steamrolla
steamrolla

Reputation: 2491

Rather than using ASP.NET Core Identity, have you explored options with something like the cookie middleware?

You could run your own queries and get navigation properties with .Includes(), then build your own ClaimsPrincipal.

Upvotes: 0

Related Questions