IdentityServer / IdentityServer3.AspNetIdentity

ASP.NET Identity support for Thinktecture IdentityServer3
Apache License 2.0
64 stars 51 forks source link

Problem when trying to use default Asp.Net entities. #32

Closed adrianorc closed 9 years ago

adrianorc commented 9 years ago

Hi,

I'm trying to set up IdentityServer3 and AspNetIdentity with the default entities of Asp.net Identity as following:


public static class UserServiceExtensions
{
    public static void ConfigureUserService(this IdentityServerServiceFactory factory, string connString)
    {
        factory.UserService = new Registration<IUserService, UserService>();
        factory.Register(new Registration<ApplicationDbContext>(resolver => new ApplicationDbContext()));
        factory.Register(new Registration<ApplicationUser>());
        factory.Register(new Registration<ApplicationUserManager>());
    }
}

public class UserService : AspNetIdentityUserService<ApplicationUser, string>
{
    public UserService(ApplicationUserManager userMgr)
        : base(userMgr)
    {
    }
}

When I run the application and click in application permissions, for exemple, an error message appears:

{"None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Usuarios.ApplicationUserManager' can be invoked with the available services and parameters:\r\nCannot resolve parameter 'Microsoft.AspNet.Identity.IUserStore1[Usuarios.Models.ApplicationUser] store' of constructor 'Void .ctor(Microsoft.AspNet.Identity.IUserStore1[Usuarios.Models.ApplicationUser])'."}

I can't figure out what I'm doing wrong.

brockallen commented 9 years ago

I think you forgot to register a IUserStore in the registration system. I suspect this line:

factory.Register(new Registration<ApplicationUser>());

was a typo.

adrianorc commented 9 years ago

Well, in fact I had to redeclare all classes of asp.net.identity.core as following:


public static class UserServiceExtensions
{
    public static void ConfigureUserService(this IdentityServerServiceFactory factory, string connString)
    {
        factory.UserService = new Registration<IUserService, UserService>();
        factory.Register(new Registration<UserManager>());
        factory.Register( new Registration<UserStore>() );
        factory.Register(new Registration<ApplicationDbContext>());
    }
}

public class UserService : AspNetIdentityUserService<ApplicationUser, string>
{
    public UserService(UserManager userMgr)
        : base(userMgr)
    {
    }
}

public class UserStore : UserStore<ApplicationUser>
{
    public UserStore(ApplicationDbContext ctx)
        : base(ctx)
    {

    }
}

public class UserManager : ApplicationUserManager
{
    public UserManager(UserStore store)
        : base(store)
    {

    }
}

Now it works.

Anyway, thanks for you attention.