예제 #1
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                });
            });

            // used to redirect to the main admin page visiting the root of the host
            app.Run(ctx =>
            {
                ctx.Response.Redirect("/idm/");
                return(Task.FromResult(0));
            });
        }
        public IdentityManagerOptions GetManagerOptions()
        {
            var factory = new IdentityManagerServiceFactory
            {
                IdentityManagerService = new Registration<IIdentityManagerService>(ctx => identityManagerService)
            };

            var rand = new Random();

            var users = UserSeeder.Get(rand.Next(1000, 3000));
            var roles = RoleSeeder.Get(rand.Next(15));
            factory.Register(new Registration<ICollection<InMemoryUser>>(users));
            factory.Register(new Registration<ICollection<InMemoryRole>>(roles));

            return new IdentityManagerOptions
            {
                Factory = factory,
                SecurityConfiguration = new HostSecurityConfiguration
                {
                    HostAuthenticationType = "Cookies",
                    NameClaimType = "name",
                    RoleClaimType = "role",
                    AdminRoleName = "IdentityManagerAdmin"
                }
            };
        }
예제 #3
0
        public IdentityManagerOptions GetManagerOptions()
        {
            var factory = new IdentityManagerServiceFactory
            {
                IdentityManagerService = new Registration <IIdentityManagerService>(ctx => identityManagerService)
            };

            var rand = new Random();

            var users = UserSeeder.Get(rand.Next(1000, 3000));
            var roles = RoleSeeder.Get(rand.Next(15));

            factory.Register(new Registration <ICollection <InMemoryUser> >(users));
            factory.Register(new Registration <ICollection <InMemoryRole> >(roles));

            return(new IdentityManagerOptions
            {
                Factory = factory,
                SecurityConfiguration = new HostSecurityConfiguration
                {
                    HostAuthenticationType = "Cookies",
                    NameClaimType = "name",
                    RoleClaimType = "role",
                    AdminRoleName = "IdentityManagerAdmin"
                }
            });
        }
        public void Configuration(IAppBuilder app)
        {
            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityMode = SecurityMode.LocalMachine,
                    OAuth2Configuration = new OAuth2Configuration
                    {
                        AuthorizationUrl = "http://localhost:17457/ids/connect/authorize",
                        Issuer = "https://idsrv3.com",
                        Audience = "https://idsrv3.com/resources",
                        ClientId = "idmgr",
                        SigningCert = Cert.Load(),
                        Scope = "idmgr",
                        ClaimsTransformation = user =>
                        {
                            if (user.IsInRole("Foo"))
                            {
                                ((ClaimsIdentity)user.Identity).AddClaim(new Claim("role", "IdentityManagerAdministrator"));
                            }
                            
                            return user;
                        },
                        //PersistToken = true,
                        //AutomaticallyRenewToken = true
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });

            // used to redirect to the main admin page visiting the root of the host
            app.Run(ctx =>
            {
                ctx.Response.Redirect("/idm/");
                return System.Threading.Tasks.Task.FromResult(0);
            });
        }
예제 #5
0
        public void Configuration(IAppBuilder app)
        {
            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory             = factory,
                    SecurityMode        = SecurityMode.LocalMachine,
                    OAuth2Configuration = new OAuth2Configuration
                    {
                        AuthorizationUrl     = "http://localhost:17457/ids/connect/authorize",
                        Issuer               = "https://idsrv3.com",
                        Audience             = "https://idsrv3.com/resources",
                        ClientId             = "idmgr",
                        SigningCert          = Cert.Load(),
                        Scope                = "idmgr",
                        ClaimsTransformation = user =>
                        {
                            if (user.IsInRole("Foo"))
                            {
                                ((ClaimsIdentity)user.Identity).AddClaim(new Claim("role", "IdentityManagerAdministrator"));
                            }

                            return(user);
                        },
                        //PersistToken = true,
                        //AutomaticallyRenewToken = true
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });

            // used to redirect to the main admin page visiting the root of the host
            app.Run(ctx =>
            {
                ctx.Response.Redirect("/idm/");
                return(System.Threading.Tasks.Task.FromResult(0));
            });
        }
예제 #6
0
 public static void ConfigureSimpleIdentityManagerService(this IdentityManagerServiceFactory factory, string connectionString)
 {
     factory.Register(new Registration <MacheteContext>(resolver => new MacheteContext(connectionString)));
     factory.Register(new Registration <UserStore>());
     factory.Register(new Registration <RoleStore>());
     factory.Register(new Registration <UserManager>());
     factory.Register(new Registration <RoleManager>());
     factory.IdentityManagerService = new Registration <IIdentityManagerService, SimpleIdentityManagerService>();
 }
예제 #7
0
 public static void ConfigureSimpleIdentityManagerService(this IdentityManagerServiceFactory factory)
 {
     factory.Register(new Registration <AuthDbContext>(resolver => new AuthDbContext()));
     factory.Register(new Registration <UserStore>());
     factory.Register(new Registration <RoleStore>());
     factory.Register(new Registration <UserManager>());
     factory.Register(new Registration <RoleManager>());
     factory.IdentityManagerService = new Registration <IIdentityManagerService, IdentityManagerService>();
 }
예제 #8
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>();
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
            {
                Authority                  = "https://localhost:44337/ids",
                ClientId                   = "idmgr_client",
                RedirectUri                = "https://localhost:44337",
                ResponseType               = "id_token",
                UseTokenLifetime           = false,
                Scope                      = "openid idmgr",
                SignInAsAuthenticationType = "Cookies"
            });

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "Cookies"
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });

            // used to redirect to the main admin page visiting the root of the host
            app.Run(ctx =>
            {
                ctx.Response.Redirect("/idm/");
                return(Task.FromResult(0));
            });
        }
예제 #9
0
 public static void ConfigureCustomIdentityManagerServiceWithIntKeys(this IdentityManagerServiceFactory factory, string connectionString)
 {
     factory.Register(new Registration <CustomContext>(resolver => new CustomContext(connectionString)));
     factory.Register(new Registration <CustomUserStore>());
     factory.Register(new Registration <CustomRoleStore>());
     factory.Register(new Registration <CustomUserManager>());
     factory.Register(new Registration <CustomRoleManager>());
     factory.IdentityManagerService = new Registration <IIdentityManagerService, CustomIdentityManagerServiceWithIntKeys>();
 }
        public static void ConfigureIdentityManagerService(this IdentityManagerServiceFactory factory, string connectionString)
        {
            factory.Register(new Registration <CContext>(resolver => new CContext(connectionString)));
            factory.Register(new Registration <CUserStore>());
            factory.Register(new Registration <CRoleStore>());
            factory.Register(new Registration <CUserManager>());
            factory.Register(new Registration <CRoleManager>());
            factory.IdentityManagerService = new Registration <IIdentityManagerService, CIdentityManagerService>();

            ConfigureUser(Users.Get(), connectionString);
        }
예제 #11
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",
                Authority = "https://localhost:44337/ids",
                ClientId = "idmgr_client",
                RedirectUri = "https://localhost:44337",
                ResponseType = "id_token",
                UseTokenLifetime = false,
                Scope = "openid idmgr",
                SignInAsAuthenticationType = "Cookies"
            });

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "Cookies",
                        //AdditionalSignOutType = "oidc"
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });
        }
        public static void ConfigureSimpleIdentityManagerService(this IdentityManagerServiceFactory factory)
        {
            factory.Register(new Registration <DbContext>(resolver => new ApplicationDbContext()));
            factory.Register(new Registration <IUserStore <ApplicationUser>, UserStore <ApplicationUser> >());
            factory.Register(new Registration <ApplicationUserManager>(
                                 resolver => ApplicationUserManager.CreateUserManager(
                                     new IdentityFactoryOptions <ApplicationUserManager>(),
                                     resolver.Resolve <DbContext>(),
                                     new EmailService(),
                                     new SmsService())));
            factory.Register(new Registration <IRoleStore <ApplicationRole, string>, RoleStore <ApplicationRole> >());
            factory.Register(new Registration <ApplicationRoleManager>());

            factory.IdentityManagerService = new Registration <IIdentityManagerService, ApplicationIdentityManagerService>();
        }
예제 #13
0
 public void Configuration(IAppBuilder app)
 {
     ConfigureAuth(app);
     app.Map("/idm", idm => {
         var factory = new IdentityManagerServiceFactory();
         factory.IdentityManagerService = new Registration <IIdentityManagerService, ApplicationIdentityManagerService>();
         factory.Register(new Registration <ApplicationUserManager>());
         factory.Register(new Registration <ApplicationUserStore>());
         factory.Register(new Registration <ApplicationRoleManager>());
         factory.Register(new Registration <ApplicationRoleStore>());
         factory.Register(new Registration <ApplicationDbContext>());
         idm.UseIdentityManager(new IdentityManagerOptions
         {
             Factory = factory
         });
     });
 }
예제 #14
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                });
            });
        }
예제 #15
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = "Cookies",
                LoginPath          = new PathString("/Home/Login")
            });

            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration()
                    {
                        HostAuthenticationType = "Cookies",
                        NameClaimType          = "name",
                        RoleClaimType          = "role",
                        AdminRoleName          = "admin"
                    }
                });
            });
        }
예제 #16
0
        public void Configuration(IAppBuilder app)
        {
            AppStart();
            ConfigureAuth(app);
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.IdentityManagerService =
                new Registration<IIdentityManagerService,
                ApplicationIdentityManagerService>();

                factory.Register(new Registration<ApplicationUserManager>());
                factory.Register(new Registration<ApplicationUserStore>());
                factory.Register(new Registration<ApplicationRoleManager>());
                factory.Register(new Registration<ApplicationRoleStore>());
                //factory.Register(new Registration<ApplicationDbContext>(resolver => new ApplicationDbContext("foo")));
                factory.Register(new Registration<ApplicationDbContext>());

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory
                });
            });
        }
예제 #17
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                });
            });
        }
 public static void Configure(this IdentityManagerServiceFactory factory, string connectionString)
 {
     factory.IdentityManagerService = new Registration <IIdentityManagerService, CustomIdentityManagerService>();
     factory.Register(new Registration <CustomUserAccountService>());
     factory.Register(new Registration <CustomGroupService>());
     factory.Register(new Registration <CustomUserRepository>());
     factory.Register(new Registration <CustomGroupRepository>());
     factory.Register(new Registration <CustomDatabase>(resolver => new CustomDatabase(connectionString)));
     factory.Register(new Registration <CustomConfig>(CustomConfig.Config));
 }
        public static void ReConfigureDefaultFactory(IdentityManagerServiceFactory factory, string connectionStringName)
        {
            factory.IdentityManagerService = new Registration <IIdentityManagerService, CustomIdentityManagerService>();
            factory.Register(new Registration <CustomUserAccountService>());
            factory.Register(new Registration <CustomGroupService>());

            factory.Register(new Registration <CustomUserRepository>());
            factory.Register(new Registration <CustomGroupRepository>());

            factory.Register(new Registration <CustomDatabase>(resolver => new CustomDatabase(connectionStringName)));
            factory.Register(new Registration <CustomConfiguration>(CustomConfiguration.Data));
        }
        public static IdentityManagerServiceFactory Configure(this IdentityManagerServiceFactory factory,
                                                              string connectionString)
        {
            factory.Register(new Registration <Context>(resolver => new Context(connectionString)));
            factory.Register(new Registration <UserStore>());
            factory.Register(new Registration <RoleStore>());
            factory.Register(new Registration <UserManager>());
            factory.Register(new Registration <RoleManager>());
            var clientstore = new ClientStore(new ClientsDbContext(connectionString));

            factory.Register(new Registration <IClientStore>(clientstore));

            factory.IdentityManagerService = new Registration <IIdentityManagerService, IdentityManagerService>();

            return(factory);
        }
    public static IdentityManagerServiceFactory Configure(string connString)
    {
      var factory = new IdentityManagerServiceFactory();

      ConfigureUsers(DefaultUsers.Get(), connString);

      factory.IdentityManagerService = new Registration<IIdentityManagerService, CustomIdentityManagerService>();
      factory.Register(new Registration<CustomUserAccountService>());
      factory.Register(new Registration<CustomGroupService>());
      factory.Register(new Registration<CustomUserRepository>());
      factory.Register(new Registration<CustomGroupRepository>());
      factory.Register(new Registration<CustomDatabase>(resolver => new CustomDatabase(connString)));
      factory.Register(new Registration<CustomConfig>(CustomConfig.Config));

      return factory;
    }
        public static IdentityManagerServiceFactory Configure(string connString)
        {
            var factory = new IdentityManagerServiceFactory();

            ConfigureUsers(DefaultUsers.Get(), connString);

            factory.IdentityManagerService = new Registration <IIdentityManagerService, CustomIdentityManagerService>();
            factory.Register(new Registration <CustomUserAccountService>());
            factory.Register(new Registration <CustomGroupService>());
            factory.Register(new Registration <CustomUserRepository>());
            factory.Register(new Registration <CustomGroupRepository>());
            factory.Register(new Registration <CustomDatabase>(resolver => new CustomDatabase(connString)));
            factory.Register(new Registration <CustomConfig>(CustomConfig.Config));

            return(factory);
        }
        public IdentityManagerOptions GetManagerOptions()
        {
            var factory = new IdentityManagerServiceFactory();

            factory.IdentityManagerService = new Registration <IIdentityManagerService, CustomIdentityManagerService>();
            factory.Register(new Registration <CustomUserAccountService>());
            factory.Register(new Registration <CustomGroupService>());
            factory.Register(new Registration <CustomUserRepository>());
            factory.Register(new Registration <CustomGroupRepository>());
            factory.Register(new Registration <CustomDatabase>(resolver => new CustomDatabase("MembershipReboot")));
            factory.Register(new Registration <CustomConfig>(CustomConfig.Config));

            return(new IdentityManagerOptions
            {
                Factory = factory,
                SecurityConfiguration = new HostSecurityConfiguration
                {
                    HostAuthenticationType = "Cookies",
                    NameClaimType = "name",
                    RoleClaimType = "role",
                    AdminRoleName = "IdentityManagerAdmin"
                }
            });
        }
        public IdentityManagerOptions GetManagerOptions()
        {
            var factory = new IdentityManagerServiceFactory();

            factory.IdentityManagerService = new Registration<IIdentityManagerService, CustomIdentityManagerService>();
            factory.Register(new Registration<CustomUserAccountService>());
            factory.Register(new Registration<CustomGroupService>());
            factory.Register(new Registration<CustomUserRepository>());
            factory.Register(new Registration<CustomGroupRepository>());
            factory.Register(new Registration<CustomDatabase>(resolver => new CustomDatabase("MembershipReboot")));
            factory.Register(new Registration<CustomConfig>(CustomConfig.Config));

            return new IdentityManagerOptions
            {
                Factory = factory,
                SecurityConfiguration = new HostSecurityConfiguration
                {
                    HostAuthenticationType = "Cookies",
                    NameClaimType = "name",
                    RoleClaimType = "role",
                    AdminRoleName = "IdentityManagerAdmin"
                }
            };
        }
예제 #25
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies",
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",
                Authority = "https://localhost:44337/ids",
                ClientId = "idmgr_client",
                RedirectUri = "https://localhost:44337",
                ResponseType = "id_token",
                UseTokenLifetime = false,
                Scope = "openid idmgr",
                SignInAsAuthenticationType = "Cookies",
                Notifications = new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = n =>
                    {
                        n.AuthenticationTicket.Identity.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));
                        return Task.FromResult(0);
                    },
                    RedirectToIdentityProvider = async n =>
                    {
                        if (n.ProtocolMessage.RequestType == Microsoft.IdentityModel.Protocols.OpenIdConnectRequestType.LogoutRequest)
                        {
                            var result = await n.OwinContext.Authentication.AuthenticateAsync("Cookies");
                            if (result != null)
                            {
                                var id_token = result.Identity.Claims.GetValue("id_token");
                                if (id_token != null)
                                {
                                    n.ProtocolMessage.IdTokenHint = id_token;
                                    n.ProtocolMessage.PostLogoutRedirectUri = "https://localhost:44337/idm";
                                }
                            }
                        }
                    }
                }
            });

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "Cookies",
                        //AdditionalSignOutType = "oidc"
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });
        }
예제 #26
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            app.UseCookieAuthentication(new CookieAuthenticationOptions() {
                AuthenticationType = "Cookies",
                LoginPath = new PathString("/Home/Login")
            });

            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration() {
                        HostAuthenticationType = "Cookies",
                        NameClaimType = "name",
                        RoleClaimType = "role",
                        AdminRoleName = "admin"
                    }
                });
            });
        }
예제 #27
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>();
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies",
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",
                Authority          = "https://localhost:44337/ids",
                ClientId           = "idmgr_client",
                RedirectUri        = "https://localhost:44337",
                ResponseType       = "id_token",
                UseTokenLifetime   = false,
                Scope = "openid idmgr",
                SignInAsAuthenticationType = "Cookies",
                Notifications = new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenValidated = n =>
                    {
                        n.AuthenticationTicket.Identity.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));
                        return(Task.FromResult(0));
                    },
                    RedirectToIdentityProvider = async n =>
                    {
                        if (n.ProtocolMessage.RequestType == Microsoft.IdentityModel.Protocols.OpenIdConnectRequestType.LogoutRequest)
                        {
                            var result = await n.OwinContext.Authentication.AuthenticateAsync("Cookies");
                            if (result != null)
                            {
                                var id_token = result.Identity.Claims.GetValue("id_token");
                                if (id_token != null)
                                {
                                    n.ProtocolMessage.IdTokenHint           = id_token;
                                    n.ProtocolMessage.PostLogoutRedirectUri = "https://localhost:44337/idm";
                                }
                            }
                        }
                    }
                }
            });

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand  = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration <ICollection <InMemoryUser> >(users));
                factory.Register(new Registration <ICollection <InMemoryRole> >(roles));
                factory.IdentityManagerService = new Registration <IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "Cookies",
                        //AdditionalSignOutType = "oidc"
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });
        }
예제 #28
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.IdentityManagerService = new Registration<IIdentityManagerService, ApplicationIdentityManagerService>();
                factory.Register(new Registration<ApplicationUserManager>());
                factory.Register(new Registration<ApplicationUserStore>());
                factory.Register(new Registration<ApplicationRoleManager>());
                factory.Register(new Registration<ApplicationRoleStore>());
                factory.Register(new Registration<ApplicationDbContext>());

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory
                });
            });
        }
예제 #29
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.IdentityManagerService = new Registration <IIdentityManagerService, ApplicationIdentityManagerService>();
                factory.Register(new Registration <ApplicationUserManager>());
                factory.Register(new Registration <ApplicationUserStore>());
                factory.Register(new Registration <ApplicationRoleManager>());
                factory.Register(new Registration <ApplicationRoleStore>());
                factory.Register(new Registration <ApplicationDbContext>());

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory
                });
            });
        }