Sean
Sean

Reputation: 15144

UserManager does not contain a definition for CreateIdentity

I'm trying to migrate this code to ASP.NET V5:

    public ClaimsIdentity GenerateUserIdentity(UserManager<User> manager, string authenticationType)
    {
        var userIdentity = manager.CreateIdentity(this, authenticationType);
        ...

I'm getting the error UserManager<User> does not contain a definition for CreateIdentity

Any ideas how to fix it?

Upvotes: 3

Views: 1225

Answers (1)

K&#233;vin Chalet
K&#233;vin Chalet

Reputation: 42010

To create a ClaimsPrincipal from a TUser object, you can import IUserClaimsPrincipalFactory<TUser> in your own code and call CreateAsync:

var principal = await factory.CreateAsync(user);

Alternatively, you can also use UserManager<TUser>.GetClaimsAsync - which is what UserClaimsPrincipalFactory<TUser> uses behind the scenes - and create a ClaimsIdentity yourself:

var identity = new ClaimsIdentity(await manager.GetClaimsAsync(user), authenticationType);

Upvotes: 4

Related Questions