Search code examples
c#asp.net-mvcidentityowinclaims

Trying to override CreateAsync function on ClaimsIdentityFactory


Few days ago, I found a very good tutorial about MVC, Identity and OWIN by Ben Foster. The tutorial is here

I've just finished the tutorial, and I've found a problem trying to override the function 'CreateAsync'. Visual Studio doesn't allow this.

This is the code:

public class AppUserClaimsIdentityFactory : ClaimsIdentityFactory<AppUser>
{
    public override async Task<ClaimsIdentity> CreateAsync(
        UserManager<AppUser> manager, 
        AppUser user, 
        string authenticationType)
    {
        var identity = await base.CreateAsync(manager, user, authenticationType);
        identity.AddClaim(new Claim(ClaimTypes.Country, user.Country));

        return identity;
    }
}

Anybody knows how can I resolve this issue?

Solution

Thanks to @ETorre, that's the final code!

public class AppUserClaimsIdentityFactory : ClaimsIdentityFactory<AppUser, string>
{
    public async override Task<ClaimsIdentity> CreateAsync(UserManager<AppUser, string> manager, 
            AppUser user, string authenticationType)
    {
        var identity = await base.CreateAsync(manager, user, authenticationType);
        identity.AddClaim(new Claim(ClaimTypes.Country, user.Country));

        return identity;
    }
}

Solution

  • You can try to see the version? the files on git use Microsoft.AspNet.Identity.Core.dll version 1 and now it's the vervion 2. Try to innerit of ClaimsIdentityFactory