1

In My Project I'm Using Repository pattern, So I Want to use my Own class instead of ApplicationUser Class.

So I have Customize the DbContext Class accordingly.

This is my class which I want to use in place of ApplicationUser.

public class AppUser : IdentityUser
    {
        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Email { get; set; }

        public string ConfirmationCode { get; set; }

        public DateTime ConfirmationCodeSentDate { get; set; }

        [Key]
        public int Identifier {get;set;}

        public DateTime DateCreated  { get; set; }

        public DateTime LastModified {get; set;}

        public bool IsRemoved {   get;  set;}
    }

My Context Class is as follow.

public class TestArchDbContext : IdentityDbContext<AppUser>
    {
        public TestArchDbContext()
            : base("TestArchDb")
        {

        }
        public IDbSet<Result> Results { get; set; }
        public static TestArchDbContext Create()    
        {
            return new TestArchDbContext();
        }
    }

Now There is code in GetExternalLogin Method in AccountController

 AppUser user = await UserManager.FindAsync(new UserLoginInfo(externalLogin.LoginProvider,
                externalLogin.ProviderKey));

 ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(UserManager,
                    OAuthDefaults.AuthenticationType);
                ClaimsIdentity cookieIdentity = await user.GenerateUserIdentityAsync(UserManager,
                    CookieAuthenticationDefaults.AuthenticationType);

I'm getting error that AppUser doesn't contain the defination of GenerateUserIdentityAsync.

Where do I have to write this method.

Amit Kumar
  • 5,888
  • 11
  • 47
  • 85
  • You are probably going to have to implement that functionality. Take a look at the accepted answer this post (near the bottom of the answer): http://stackoverflow.com/questions/24428520/identity-2-0-with-custom-tables – Mikanikal Apr 01 '16 at 03:17
  • @AmitKumar: Why don't you just add your own properties to the existing `ApplicationUser`? – Stephen Cleary Apr 01 '16 at 12:26

1 Answers1

0

I added a method to my controller, And it solved my problem.

 public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<AppUser> manager, AppUser user, string authenticationType)
        {         
            var userIdentity = await manager.CreateIdentityAsync(user, authenticationType); 
            return userIdentity;
        }

Then call this method (instead of calling from AppUser object, call it directly, and pass the user Object.

 ClaimsIdentity oAuthIdentity = await this.GenerateUserIdentityAsync(UserManager,user,
                    OAuthDefaults.AuthenticationType);
                ClaimsIdentity cookieIdentity = await GenerateUserIdentityAsync(UserManager,user,
                    CookieAuthenticationDefaults.AuthenticationType);
Amit Kumar
  • 5,888
  • 11
  • 47
  • 85