IdentityManager与VNext

时间:2015-06-12 21:20:09

标签: asp.net asp.net-core-mvc thinktecture

是否有人尝试将IdentityManager与vNext一起使用?

我遇到了app.UseIdentityManager(IdentityManagerOptions)扩展方法的问题。

它不存在。

所以我尝试使用为UseIdentityServer(找到here)所做的扩展方法,将所有与服务器相关的方面更改为manager。 当我这样做时,我会在第43行得到System.NullReferenceException

关于如何使用扩展方法的任何建议都将非常感激

2 个答案:

答案 0 :(得分:0)

我正在使用ASPNET 5 beta6,我开始使用它。

尝试使用dev分支上的Samples repo中的this更新的IApplicationBuilder扩展名。重新调整方法以接受IdentityManagerOptions而不是IdentityServerOptions,并将构建器编辑为UseIdentityManager

总之,这是我的扩展方法的样子

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;
            });
        });
    }
}

答案 1 :(得分:-2)

我正在使用vNext而且我注意到许多事情已经发生变化并且会继续发生变化。

为了我自己的需要,我已经能够轻松地获得身份和运行,并且我必须采取两个步骤才能使其正常运行。我所做的也应该适合你。

在StartUp.cs中,您需要确保将以下内容添加到ConfigureServices方法中:

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

除此之外,您还需要将应用配置为使用身份,并且需要在Configure()方法中执行以下操作:

app.UseIdentity();