tugberkugurlu / AspNet.Identity.RavenDB

Fully asynchronous, new and sweet ASP.NET Identity implementation for RavenDB
MIT License
42 stars 28 forks source link

Question, use OWIN? #30

Closed WilliamDoman closed 10 years ago

WilliamDoman commented 10 years ago

Has anybody got this working in the OWIN pipeline?

I'm trying to mimic the EF implementation, per owin request. Unless theres a better way...

app.CreatePerOwinContext<AppUserIdentityDbContext>(AppUserIdentityDbContext.Create);
app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);

Where AppUserManager : UserManager and

 public static AppUserManager Create(IdentityFactoryOptions<AppUserManager> options, IOwinContext context)
        {
            return = new AppUserManager(new UserStore<AppUserIdentity>(context.Get<AppUserIdentityDbContext>()));
}  
jakvike commented 10 years ago

Here is my UserManager which is creating a user within RavenDB. FYI ApplicationUser is inheriting from RavenUser.

public class ApplicationUserManager : UserManager { public ApplicationUserManager(RavenUserStore userStore) : base(userStore) { }

    public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
    {
        var session = context.Get<IAsyncDocumentSession>();
        session.Advanced.UseOptimisticConcurrency = true;
        var manager = new ApplicationUserManager(new RavenUserStore<ApplicationUser>(session));

        manager.UserValidator = new UserValidator<ApplicationUser>(manager)
        {
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true
        };

        manager.UserLockoutEnabledByDefault = true;
        manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
        manager.MaxFailedAccessAttemptsBeforeLockout = 5;
        manager.EmailService = new EmailService();
        manager.PasswordValidator = new PasswordValidator
        {
            RequiredLength = 8,
            RequireNonLetterOrDigit = true,
            RequireDigit = true,
            RequireLowercase = false,
            RequireUppercase = false,
        };

        var dataProtectionProvider = options.DataProtectionProvider;
        if (dataProtectionProvider != null)
        {
            manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
        }

        return manager;
    }
jakvike commented 10 years ago

This is within the startup.Auth

app.CreatePerOwinContext(ApplicationSession.Create); app.CreatePerOwinContext(ApplicationUserManager.Create);

WilliamDoman commented 10 years ago

@jakvike Thanks! What does your ApplicationSession.Create look like? I'm a raven noobie.

jakvike commented 10 years ago

public class ApplicationSession : IDisposable { public static IAsyncDocumentSession Create() { return MvcApplication.Store.OpenAsyncSession(); }

    public void Dispose()
    {
        MvcApplication.Store.Dispose();
    }
}

Global.asax

public class MvcApplication : System.Web.HttpApplication { public static IDocumentStore Store;

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        Store = new DocumentStore { ConnectionStringName = "RavenDB" };
        Store.Initialize();

        IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), Store);
    }
}
jakvike commented 10 years ago

You and I both are Noobs!

WilliamDoman commented 10 years ago

@jakvike

Thanks! that was a big big big help

jakvike commented 10 years ago

You are welcome!

Thank you,

Jake Kapp

On Thu, Apr 24, 2014 at 3:50 PM, William Doman notifications@github.comwrote:

@jakvike https://github.com/jakvike

Thanks! that was a big big big help

— Reply to this email directly or view it on GitHubhttps://github.com/tugberkugurlu/AspNet.Identity.RavenDB/issues/30#issuecomment-41330364 .