コード例 #1
0
 public static void ConfigureIdentity() 
 {
     var dbContextCreator = new DbContextFactory<IdentityDbContext>();
     Secrets = new EFUserSecretStore<UserSecret>(dbContextCreator);
     Logins = new EFUserLoginStore<UserLogin>(dbContextCreator);
     Users = new EFUserStore<User>(dbContextCreator);
     Roles = new EFRoleStore<Role, UserRole>(dbContextCreator);
     RoleClaimType = ClaimsIdentity.DefaultRoleClaimType;
     UserIdClaimType = "http://schemas.microsoft.com/aspnet/userid";
     UserNameClaimType = "http://schemas.microsoft.com/aspnet/username";
     ClaimsIssuer = ClaimsIdentity.DefaultIssuer;
     //AntiForgeryConfig.UniqueClaimTypeIdentifier = IdentityConfig.UserIdClaimType;
 }
コード例 #2
0
        public static void ConfigureIdentity()
        {
            var dbContextCreator = new DbContextFactory <ShoelaceDbContext>();

            Secrets           = new EFUserSecretStore <UserSecret>(dbContextCreator);
            Logins            = new EFUserLoginStore <UserLogin>(dbContextCreator);
            Users             = new EFUserStore <User>(dbContextCreator);
            Roles             = new EFRoleStore <Role, UserRole>(dbContextCreator);
            RoleClaimType     = ClaimsIdentity.DefaultRoleClaimType;
            UserIdClaimType   = "http://schemas.microsoft.com/aspnet/userid";
            UserNameClaimType = "http://schemas.microsoft.com/aspnet/username";
            ClaimsIssuer      = ClaimsIdentity.DefaultIssuer;
            AntiForgeryConfig.UniqueClaimTypeIdentifier = IdentityConfig.UserIdClaimType;
        }
コード例 #3
0
 public static void Execute(HttpContextBase httpContext, string username)
 {
     var user = new User(username);
       var userStore = new EFUserStore<User>(new DbContextFactory<MonopolyDotNetDbContext>());
       //I tried adding a task.Wait() after this call to make sure this create call finishes, but it seems like
       //either I'm doing something horribly wrong (?) or the framework code isn't setting the task to Completed status after done.
       //I really really don't know, but I DO know that if I uncomment that task.Wait() call, it will wait forever, and I DO know
       //that the correct way to "wait for an async task to finish" is to use task.Wait(), so I'm just leaving this here with this
       //longwinded comment that absolves me of all responsibility. You Have Been Warned.
       //
       //I also tried task.GetAwaiter().GetResult(); -- no dice.
       //
       //It's probably because I'm using preview code (not even RC).
       var task = userStore.Create(user);
       //task.GetAwaiter().GetResult();
       //task.Wait();
       var userClaims = GetNewUserIdentityClaims(user.Id, user.UserName);
       SignIn(httpContext, userClaims, false);
 }
コード例 #4
0
        protected override void Seed(ShoelaceMVC.Models.ShoelaceDbContext context)
        {
            //  This method will be called after migrating to the latest version.
            var  dbContextCreator = new DbContextFactory <ShoelaceDbContext>();
            var  Secrets          = new EFUserSecretStore <UserSecret>(dbContextCreator);
            var  Logins           = new EFUserLoginStore <UserLogin>(dbContextCreator);
            var  Users            = new EFUserStore <User>(dbContextCreator);
            var  Roles            = new EFRoleStore <Role, UserRole>(dbContextCreator);
            var  userName         = "******";
            User user             = new User(userName);

            Users.Create(user);
            Roles.AddUserToRole("Admin", userName);
            //**********************************************************************************************/
            // TODO: Change the admin password from "password" to something else RIGHT NOW!
            // Sketchy hacker dudes are totally gonna guess that!
            //**********************************************************************************************/
            Secrets.Create(new UserSecret(userName, "password"));  //<<<================
            Logins.Add(new UserLogin(user.Id, IdentityConfig.LocalLoginProvider, userName));

            var admin = context.Users.First(x => x.UserName == userName);

            // "localhost" as the domain will allow you to run the app locally and test using the demo account.
            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
            context.Accounts.Add(new ShoelaceMVC.Models.Account()
            {
                Name = "Demo", Owner = admin, Subdomain = "demo", VanityDomain = "localhost"
            });
        }