0

At some point in the life cycle of an authenticated ASP.NET request the IdentityUser is retrieved from the backing store (either Entity Framework or otherwise). I'd like to hook into that process. The reason is that the user has some collection properties and I'd like to retrieve those as well with one call to the database (using IQueryable<T>.Include).

Is this possible in ASP.NET identity?

Sebazzz
  • 1,205
  • 2
  • 15
  • 33

2 Answers2

0

I think you probably want to implement a ClaimsAuthenticationManager

The claims authentication manager provides a place in the claims processing pipeline for applying processing logic (filtering, validation, extension) to the claims collection in the incoming principal before execution reaches your application code.

Since what you're looking for sounds like extension to me. You override the Authenticate method that has this signature:

public virtual ClaimsPrincipal Authenticate(
    string resourceName,
    ClaimsPrincipal incomingPrincipal
)
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • I believe this is an step in the right direction. I actually found out a few things. When you are logged in, a cookie is created with some claims in them: your roles (the names) and your user name. If the cookie is present and valid (ie: decryptable, sigature is valid), you're assumed to be logged in and OK. This means your roles and even you existence in the system may go stale! There are actually no database calls of any kind performed since the authentication mechanism doesn't know about ASP.NET Identity. You can try this easily yourself. Create a user, log in as that user, and delete it. – Sebazzz Mar 01 '14 at 21:59
0

You probably want to override UserStore and override all of the FindXXX methods that return a User do add whatever Includes that you wanted.

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • This is not a viable solution since it would apply to all users or I'd have to check in every method whether to include anything. – Sebazzz Mar 01 '14 at 21:58