IdentityManager with VNext

662 views Asked by At

Has anyone tried using IdentityManager with vNext?

I'm having problems with the app.UseIdentityManager(IdentityManagerOptions) extension method.

It doesn't exist.

So I tried using the extension method made for UseIdentityServer (found here) by changing all the server related aspects to manager. When I do that, I get the System.NullReferenceException in line 43.

Any kind of advice on how to go about with the extension method will be really appreciated

2

There are 2 answers

1
Marqueone On

I'm using vNext and I've noticed that many things have changed and will continue to change.

For my own needs I've been able to get identity up and running fairly easily and there are two steps that I've had to take to get it running properly. What I've done should work for you as well.

In your StartUp.cs you will need to make sure you add the following to the ConfigureServices method:

services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

In addition to that you will need to configure your app to use identity and to do this you need to do the following in your Configure() method:

app.UseIdentity();
0
Lutando On

I am using ASPNET 5 beta6 and I got this to work.

Try using this updated IApplicationBuilder extension found in the Samples repo on dev branch. Repurpose the method to accept IdentityManagerOptions rather than IdentityServerOptions and edit the builder to UseIdentityManager

In short here is what my extension method looks like

public static class IApplicationBuilderExtensions
{
    public static void UseIdentityManager(this IApplicationBuilder app, IdentityManagerOptions options)
    {
        app.UseOwin(addToPipeline =>
        {
            addToPipeline(next =>
            {
                var builder = new AppBuilder();

                var provider = app.ApplicationServices.GetService<IDataProtectionProvider>();

                builder.Properties["security.DataProtectionProvider"] =
                    new DataProtectionProviderDelegate(purposes =>
                    {
                        var dataProtection = provider.CreateProtector(string.Join(",", purposes));
                        return new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect);
                    });

                builder.UseIdentityManager(options);

                var appFunc =
                    builder.Build(typeof (Func<IDictionary<string, object>, Task>)) as
                        Func<IDictionary<string, object>, Task>;
                return appFunc;
            });
        });
    }
}