Skip to content
This repository has been archived by the owner on Feb 15, 2018. It is now read-only.

MembershipReboot IdentityManagerService

Brock Allen edited this page Mar 16, 2015 · 6 revisions

IdentityManager.MembershipReboot

IdentityManager.MembershipReboot is an IdentityManagerService implementation for IdentityManager that uses MembershipReboot as the identity management system.

The code repository and sample host is available here.

Installing

You can either clone the code and sample host from the repository above, or you can install the NuGet via:

PM> Install-Package IdentityManager.MembershipReboot -Pre 

MembershipReboot IdentityManagerService

The MembershipRebootIdentityManagerService is an implementation of IIdentityManagerService and is designed to integrate with MembershipReboot.

It is a generic class and expects generic arguments for the user account and group types. The constructor then accepts UserAccountService, IUserAccountQuery, GroupService and IGroupQuery parameters.

Metadata

The MembershipRebootIdentityManagerService can automatically generate the necessary metadata to drive IdentityManager for the standard properties used in MembershipReboot such as username, password, email, phone and login allowed. In addition, there is a constructor parameter includeAccountProperties (which defaults to true) that will also generate the metadata for the properties of the user account class being used.

If more customization is needed, then there is an overloaded constructor that provides a delegate to create the metadata. Within this delegate it's possible to use the MembershipRebootIdentityManagerService.GetStandardMetadata to create the default metadata which can then be customized as needed.

Service factory

To integrate into the IdentityManagerConfiguration, a factory that instantiates the MembershipRebootIdentityManagerService is needed, as such:

public class MembershipRebootIdentityManagerFactory
{
    string connString;
    public MembershipRebootIdentityManagerFactory(string connString)
    {
        this.connString = connString;
    }
        
    public IIdentityManagerService Create()
    {
        var db = new CustomDatabase(connString);
        var userRepo = new DbContextUserAccountRepository<CustomDatabase, CustomUser>(db);
        userRepo.QueryFilter = RelationalUserAccountQuery<CustomUser>.Filter;
        userRepo.QuerySort = RelationalUserAccountQuery<CustomUser>.Sort;
        var userSvc = new UserAccountService<CustomUser>(MRConfig.config, userRepo);

        var groupRepo = new DbContextGroupRepository<CustomDatabase, CustomGroup>(db);
        var groupSvc = new GroupService<CustomGroup>(MRConfig.config.DefaultTenant, groupRepo);

        var idMgr = new MembershipRebootIdentityManagerService<CustomUser, CustomGroup>(userSvc, userRepo, groupSvc, groupRepo);

        return new DisposableIdentityManagerService(idMgr, db);
    }
}

Since this factory function is invoked per-HTTP request into IdentityManager, if the returned IIdentityManagerService also implements IDisposable then it will be invoked once the request is complete. The DisposableIdentityManagerService is used to wrap the MembershipRebootIdentityManagerService and call Dispose on the database context class.

Startup

To then configure the factory with the IdentityManagerConfiguration and with Katana, this code would be needed in Startup:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var factory = new Thinktecture.IdentityManager.Host.MembershipRebootIdentityManagerFactory("MembershipReboot");

        app.UseIdentityManager(new IdentityManagerConfiguration()
        {
            IdentityManagerFactory = factory.Create
        });
    }
}