简体   繁体   中英

Custom Implementation of Asp.net IDentity. GetExternalAuthenticationTypes() Returning 0 Providers

I have implemented Custom Asp.Net Identity. For the sake of using my own Database Models instead of already built in ones. For It I have custom implemented all the following classes/Interfaces.

AuthUser : IPrincipal, IUser<string>
ApplicationSignInManager : SignInManager<AuthUserMVC, string>
AuthUserManager : UserManager<AuthUserMVC>
AuthUserStore : IUserStore<AuthUserMVC>

With It im using NInject to inject required dependencies in my AccountController. Constructor signature of AccountController is

public AccountController(
            UsersRepository usersRepository,
            AuthUserManager authUserManager,
            AuthUserStore authUserStore,
            ApplicationSignInManager signInManager)
        {

            this.UsersRepository = usersRepository;
            this.SignInManager = signInManager;
            this.UserManager = authUserManager;
            this.UserStore = authUserStore;
        }

This the NInject Code for DI

kernel.Bind<IUserStore<AuthUserMVC>>().To<AuthUserStore>().InRequestScope();
kernel.Bind<IAuthenticationManager>().ToMethod((c)=>HttpContext.Current.GetOwinContext().Authentication);

While Getting Account/Login - Normal Process of Out of the Box Identity I Dont See any External Login Providers Listed. Thats because Inside the _ExternalLoginsListPartial.cshtml

Context.GetOwinContext()
  .Authentication
  .GetExternalAuthenticationTypes() 

is Returning 0 Providers. Which it Shouldn't do


My Custom implemented Code

public class ApplicationSignInManager : SignInManager<AuthUserMVC, string>
{
    public ApplicationSignInManager(
        AuthUserManager userManager, 
        IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }

    public override Task<ClaimsIdentity> CreateUserIdentityAsync(AuthUserMVC user)
    {
        return Task.FromResult(user.GetIdentity());
    }

    public static ApplicationSignInManager Create(
        IdentityFactoryOptions<ApplicationSignInManager> options, 
        IOwinContext context)
    {
        return new ApplicationSignInManager(context.GetUserManager<AuthUserManager>(), context.Authentication);
    }
}

public class AuthUserManager : UserManager<AuthUserMVC>
    {
        public AuthUserManager(IUserStore<AuthUserMVC> store) : base(store)
        {
        }

        public override Task<IdentityResult> AddClaimAsync(string userId, Claim claim)
        {
            return base.AddClaimAsync(userId, claim);
        }
    }

What am I doing wrong?

As you are probably aware, when you implement a custom AspNetIdentity provider you have to do a number of things. One of them is to implement AuthenticationOptions. If you decompile the code for the GetExternalAuthenticationTypes method you will see that part of the things it checks is that your custom AuthenticationOptions implementation has a property called "Caption". If it doesn't then it won't be returned by GetExternalAuthenticationTypes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM