public ConsentStore(EntityFrameworkServiceOptions options, IOperationalDbContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            this.options = options;
            this.context = context;
        }
示例#2
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
            };

            // these two calls just pre-populate the test DB from the in-memory config
            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            //var scopeStore = new InMemoryScopeStore(Scopes.Get());
            //factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            //var clientStore = new InMemoryClientStore(Clients.Get());
            //factory.ClientStore = new Registration<IClientStore>(clientStore);

            factory.ConfigureUserService(connString);

            factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true });

            return factory;
        }
示例#3
0
        public static IdentityServerServiceFactory Configure(ApplicationDbContext dbContext)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = dbContext.ConnectionStringName,
            };

            // these two calls just pre-populate the test DB from the in-memory config
            //running with db.Clients.Any()
            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);


            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            var viewOptions = new DefaultViewServiceOptions();
            viewOptions.Stylesheets.Add("/Content/Site.css");
            factory.ConfigureDefaultViewService(viewOptions);

            factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true });

            return factory;
        }
        public ScopeStore(EntityFrameworkServiceOptions options, IScopeConfigurationDbContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            this.options = options;
            this.context = context;
        }
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions {
                ConnectionString = connString,
                //Schema = "foo",
                //SynchronousReads = true
            };

            var cleanup = new TokenCleanup(efConfig, 10);
            cleanup.Start();

            // these two calls just pre-populate the test DB from the in-memory config
            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            //factory.ConfigureClientStoreCache();
            //factory.ConfigureScopeStoreCache();

            factory.UseInMemoryUsers(Users.Get());

            return factory;
        }
示例#6
0
        public static IdentityServerServiceFactory Configure(AppConfiguration config)
        {
            var factory = new IdentityServerServiceFactory();

            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            var clientStore = new InMemoryClientStore(Clients.Get(config));
            factory.ClientStore = new Registration<IClientStore>(clientStore);

            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = "Weee.DefaultConnection",
                Schema = "Identity"
            };

            factory.RegisterOperationalServices(efConfig);

            var cleanup = new TokenCleanup(efConfig);
            cleanup.Start();

            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Weee.DefaultConnection"].ConnectionString;
            var auditSecurityEventService = new SecurityEventDatabaseAuditor(connectionString);
            SecurityEventService eventService = new SecurityEventService(auditSecurityEventService);

            factory.Register<ISecurityEventAuditor>(new Registration<ISecurityEventAuditor>(auditSecurityEventService));
            factory.EventService = new Registration<IEventService>(eventService);

            return factory;
        }
示例#7
0
		public static async void ConfigureUsers(IEnumerable<InMemoryUser> users, EntityFrameworkServiceOptions options, UserManager userManager) {
			using(var db = new Contexto(options.ConnectionString)) {
				
				if(!db.Users.Any()) {
					
					foreach(var u in users) {
						var entity = new Usuario { Email = u.Claims.First(x=>x.Type==Constants.ClaimTypes.Email).Value , UserName = u.Username };
						var response = await userManager.CreateAsync(entity, u.Password);
						
						if(!response.Succeeded) {
							throw new Exception("Não foi possível criar o usuario" + u.Username + response.Errors.ToString());
						}
						else {
							
							var user = await userManager.FindAsync(u.Username,u.Password);
							foreach(var c in u.Claims) {

								await userManager.AddClaimAsync(user.Id,c);
							}
														
							await userManager.UpdateAsync(user);
						}
					}
					db.SaveChanges();
				}
			}
		}
    public static IdentityServerServiceFactory Configure(string connString)
    {
      var efConfig = new EntityFrameworkServiceOptions
      {
        ConnectionString = connString,
      };

      // these two calls just pre-populate the test DB from the in-memory config
      ConfigureClients(DefaultClients.Get(), efConfig);
      ConfigureScopes(DefaultScopes.Get(), efConfig);

      // ------------------------------------------------
      var factory = new IdentityServerServiceFactory();

      factory.RegisterConfigurationServices(efConfig);
      factory.RegisterOperationalServices(efConfig);

      // ----- MembershipReboot user service (pripajanie na ulozisko identit)
      factory.UserService = new Registration<IUserService, CustomUserService>();
      factory.Register(new Registration<CustomUserAccountService>());
      factory.Register(new Registration<CustomConfig>(CustomConfig.Config));
      factory.Register(new Registration<CustomUserRepository>());
      factory.Register(new Registration<CustomDatabase>(resolver => new CustomDatabase(connString)));

      return factory;
    }
示例#9
0
		/// <summary>
		/// Configura o servico do IdentityServer3 com dados do AspNetIdentity
		/// </summary>
		/// <param name="factory"></param>
		/// <param name="nameOrConnectionString"></param>
		/// <returns></returns>
		public static IdentityServerServiceFactory ConfigureIdSvrFactoryAspNet(this IdentityServerServiceFactory factory, string nameOrConnectionString) {

			var efConfig = new EntityFrameworkServiceOptions { ConnectionString = nameOrConnectionString };


			// TODO: estas tres linhas sao somente para testes devem ser removidas
			ConfigureClients(Clients.Get(), efConfig);
			ConfigureScopes(Scopes.Get(), efConfig);
			ConfigureUsers(Users.Get(), efConfig, new UserManager(new UserStore(new Contexto(nameOrConnectionString))));


			//Configura o banco de dados para armazenar os Clients e Scopes
			factory.RegisterConfigurationServices(efConfig);

			//Configura o banco de dados que armazena os dados operacionais 
			//(Ex.: authorization codes, refresh tokens, reference tokens, e user consent).
			factory.RegisterOperationalServices(efConfig);

			factory.Register(new Registration<Contexto>(resolver => new Contexto(nameOrConnectionString)));
			factory.Register(new Registration<UserStore>());
			factory.Register(new Registration<UserManager>());
			factory.UserService = new Registration<IUserService, AspNetIdUserService>();

			return factory;
		}
        public static void RegisterScopeStore(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (options == null) throw new ArgumentNullException("options");

            factory.Register(new Registration<ScopeConfigurationDbContext>(resolver => new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)));
            factory.ScopeStore = new Registration<IScopeStore, ScopeStore>();
        }
        public TokenCleanup(EntityFrameworkServiceOptions options, int interval = 60)
        {
            if (options == null) throw new ArgumentNullException("options");
            if (interval < 1) throw new ArgumentException("interval must be more than 1 second");

            this.options = options;
            this.interval = TimeSpan.FromSeconds(interval);
        }
        public ClientConfigurationCorsPolicyRegistration(EntityFrameworkServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            this.AdditionalRegistrations.Add(new Registration <ClientConfigurationDbContext>(resolver => new ClientConfigurationDbContext(options.ConnectionString, options.Schema)));
        }
        public ClientStore(EntityFrameworkServiceOptions options, IClientConfigurationDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.options = options;
            this.context = context;
        }
示例#14
0
		public static void ConfigureScopes(IEnumerable<Scope> scopes, EntityFrameworkServiceOptions options) {
			using(var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)) {
				if(!db.Scopes.Any()) {
					foreach(var s in scopes) {
						var e = s.ToEntity();
						db.Scopes.Add(e);
					}
					db.SaveChanges();
				}
			}
		}
        public static void RegisterOperationalServices(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (options == null) throw new ArgumentNullException("options");

            factory.Register(new Registration<OperationalDbContext>(resolver => new OperationalDbContext(options.ConnectionString, options.Schema)));
            factory.AuthorizationCodeStore = new Registration<IAuthorizationCodeStore, AuthorizationCodeStore>();
            factory.TokenHandleStore = new Registration<ITokenHandleStore, TokenHandleStore>();
            factory.ConsentStore = new Registration<IConsentStore, ConsentStore>();
            factory.RefreshTokenStore = new Registration<IRefreshTokenStore, RefreshTokenStore>();
        }
示例#16
0
		public static void ConfigureClients(IEnumerable<Client> clients, EntityFrameworkServiceOptions options) {
			using(var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema)) {
				if(!db.Clients.Any()) {
					foreach(var c in clients) {
						var e = c.ToEntity();
						db.Clients.Add(e);
					}
					db.SaveChanges();
				}
			}
		}
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
            };
            var factory = new IdentityServerServiceFactory();
            //Clients

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);
            return factory;
        }
        public static void RegisterClientStore(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (options == null) throw new ArgumentNullException("options");

            if (options.SynchronousReads)
            {
                factory.Register(new Registration<EntityFrameworkServiceOptions>(options));
            }

            factory.Register(new Registration<IClientConfigurationDbContext>(resolver => new ClientConfigurationDbContext(options.ConnectionString, options.Schema)));
            factory.ClientStore = new Registration<IClientStore, ClientStore>();
            factory.CorsPolicyService = new ClientConfigurationCorsPolicyRegistration(options);
        }
        public static IdentityServerServiceFactory Configure(this IdentityServerServiceFactory factory, string connectionString)
        {
            var serviceOptions = new EntityFrameworkServiceOptions { ConnectionString = connectionString };
            factory.RegisterOperationalServices(serviceOptions);
            factory.RegisterConfigurationServices(serviceOptions);
            //factory.RegisterClientStore(serviceOptions);

            factory.Register(new Registration<Context>(resolver => new Context(connectionString)));
            factory.Register(new Registration<UserStore>());
            factory.Register(new Registration<UserManager>());
            factory.UserService = new Registration<IUserService, IdentityUserService>();

            return factory;
        }
        public TokenCleanup(EntityFrameworkServiceOptions options, int interval = 60)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (interval < 1)
            {
                throw new ArgumentException("interval must be more than 1 second");
            }

            this.options  = options;
            this.interval = TimeSpan.FromSeconds(interval);
        }
示例#21
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
            };
            var factory = new IdentityServerServiceFactory()
                .UseInMemoryClients(Clients.Get())
                .UseInMemoryScopes(Scopes.Get())
                ;

            factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true });
            factory.ConfigureCustomUserService(connString);
            return factory;
        }
示例#22
0
        public static void ConfigureUsers(IEnumerable<InMemoryUser> users, EntityFrameworkServiceOptions options, MRUserAccountService userAccServic)
        {
            using(var db = new MRContext(options.ConnectionString)) {

                if(!db.Users.Any()) {

                    foreach(var u in users) {
                        var user = userAccServic.CreateAccount(u.Username, u.Password, u.Claims.First(x => x.Type == Constants.ClaimTypes.Email).Value, claims: u.Claims, dateCreated:DateTime.UtcNow);

                        if(Guid.Empty==user.ID) {
                            throw new Exception("Não foi possível criar o usuario" + u.Username);
                        }
                    }
                    db.SaveChanges();
                }
            }
        }
示例#23
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efOptions = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString
            };
            var factory = new IdentityServerServiceFactory();
            //Clients are configured in auth.api
            //Scopes are configured in auth.api
            factory.RegisterConfigurationServices(efOptions);
            factory.RegisterOperationalServices(efOptions);
            factory.RegisterScopeStore(efOptions);
            factory.RegisterClientStore(efOptions);
            factory.RegisterCors(true);

            return factory;
        }
        public static IdentityServerServiceFactory Configure(string connString, string schema)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
                Schema = schema
            };

            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            return factory;
        }
示例#25
0
        public static IdentityServerServiceFactory Configure(string idsrvConnection)
        {
            var factory = new IdentityServerServiceFactory();

            var efOptions = new EntityFrameworkServiceOptions
            {
                ConnectionString = idsrvConnection,
            };

            factory.RegisterConfigurationServices(efOptions);
            factory.RegisterOperationalServices(efOptions);
            factory.RegisterScopeStore(efOptions);
            factory.RegisterCors(true);

            factory.ConfigureUserService(idsrvConnection);

            return factory;
        }
示例#26
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
            };

            // these two calls just pre-populate the test DB from the in-memory config
            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            factory.UseInMemoryUsers(Users.Get());

            return factory;
        }
        protected BaseTokenStore(EntityFrameworkServiceOptions options, IOperationalDbContext context, TokenType tokenType, IScopeStore scopeStore, IClientStore clientStore)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (scopeStore == null)
            {
                throw new ArgumentNullException("scopeStore");
            }
            if (clientStore == null)
            {
                throw new ArgumentNullException("clientStore");
            }

            this.options     = options;
            this.context     = context;
            this.tokenType   = tokenType;
            this.scopeStore  = scopeStore;
            this.clientStore = clientStore;
        }
示例#28
0
        public static IdentityServerServiceFactory Configure(AppConfiguration config)
        {
            var factory = new IdentityServerServiceFactory();

            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            var clientStore = new InMemoryClientStore(Clients.Get(config));
            factory.ClientStore = new Registration<IClientStore>(clientStore);

            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = "Iws.DefaultConnection",
                Schema = "Identity"
            };

            factory.RegisterOperationalServices(efConfig);

            var cleanup = new TokenCleanup(efConfig);
            cleanup.Start();

            return factory;
        }
        private static void ConfigureScopes(IEnumerable<Scope> scopes, EntityFrameworkServiceOptions options)
        {
            using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema))
            {
                //if (!db.Scopes.Any())
                //{
                    foreach (var s in scopes)
                    {
                        if (db.Scopes.Any(x=>x.Name == s.Name))
                        {
                            // scope exists
                        }
                        else
                        {
                             var e = s.ToEntity();
                            db.Scopes.Add(e);
                        }

                    }
                    db.SaveChanges();
               // }
            }
        }
示例#30
0
        public void Configuration(IAppBuilder app) {

            var efConfig = new EntityFrameworkServiceOptions {
                ConnectionString = ConnectionString,
                Schema = "IdSrv"
            };

            var clientStore = new IdentityServerEfClientStore(efConfig);

            app.UseOpenIdDynamicRegistrationProtocol(clientStore);

            /* Admin is having issues...
            app.Map("/adm", adminApp => {
                var factory = new IdentityAdminServiceFactory() {
                    IdentityAdminService = new Registration<IIdentityAdminService, IdentityAdminManagerService>()
                };
                
                adminApp.UseIdentityAdmin(new IdentityAdminOptions {
                    Factory = factory
                });
            });
            */
        }
示例#31
0
        public static void ConfigureClients(IdentityServer3.Core.Models.Client client, EntityFrameworkServiceOptions options)
        {
            using (var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema))
            {
                if(db.Clients.Any()&&db.Clients.Where(x=>x.ClientId== SSOISConstants.LocalClientId).Count()>0)
                {
                    //Update Client
                    var dbClient = db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId).First();

                    if(db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId
                    && x.ClientUri== SSOISConstants.LocalClientUri).Count()==0)
                    {
                        var clt = db.Clients.Where(x => x.ClientId == SSOISConstants.LocalClientId).First();
                        clt.ClientUri = SSOISConstants.LocalClientUri;
                        db.Entry(clt).State = EntityState.Modified;
                    }

                    //Secret
                    string screct = SSOISConstants.LocalClientSecret.Sha256();
                    var lstOldSecret = db.Set<ClientSecret>().Where(x => x.Client.Id == dbClient.Id);
                    if (lstOldSecret.Where(x => x.Value == screct).Count() == 0)
                    {
                        db.Set<ClientSecret>().RemoveRange(lstOldSecret);
                        var lstNewSecret = new List<ClientSecret>() {
                        new ClientSecret() {
                            Value = SSOISConstants.LocalClientSecret.Sha256(),
                            Type = "SharedSecret",
                            Client = dbClient
                        } };
                        db.Set<ClientSecret>().AddRange(lstNewSecret);
                    }

                    //RedirectUris
                    var lstOldRed = db.Set<ClientRedirectUri>().Where(x => x.Client.Id == dbClient.Id);
                    var lstOldStrRed = lstOldRed.Select(x => x.Uri).ToList();
                    db.Set<ClientRedirectUri>().RemoveRange(lstOldRed.Where(x=> !SSOISConstants.LocalRedirectUris.Contains(x.Uri)));
                    var lstNewRed = new List<ClientRedirectUri>();
                    foreach (var sel in SSOISConstants.LocalRedirectUris)
                        if (!lstOldStrRed.Contains(sel))
                            lstNewRed.Add(new ClientRedirectUri() { Uri = sel, Client = dbClient });
                    db.Set<ClientRedirectUri>().AddRange(lstNewRed);

                    //PostLogoutRedirectUris
                    var lstOldPost = db.Set<ClientPostLogoutRedirectUri>().Where(x => x.Client.Id == dbClient.Id);
                    var lstOldStrPost = lstOldRed.Select(x => x.Uri).ToList();
                    db.Set<ClientPostLogoutRedirectUri>().RemoveRange(lstOldPost.Where(x => !SSOISConstants.LocalPostLogoutRedirectUris.Contains(x.Uri)));
                    var lstNewPost = new List<ClientPostLogoutRedirectUri>();
                    foreach (var sel in SSOISConstants.LocalPostLogoutRedirectUris)
                        if (!lstOldStrPost.Contains(sel))
                            lstNewPost.Add(new ClientPostLogoutRedirectUri() { Uri = sel, Client = dbClient });
                    db.Set<ClientPostLogoutRedirectUri>().AddRange(lstNewPost);

                    db.SaveChanges();
                }
                else
                {
                    var e = client.ToEntity();
                    db.Clients.Add(e);
                    db.SaveChanges();
                }
            }
        }
 public IdentityServerEfClientStore(EntityFrameworkServiceOptions options, IClientIdGenerator clientIdGenerator, IClientSecretGenerator secretGenerator) {
     this.options = options;
     this.clientIdGenerator = clientIdGenerator;
     this.secretGenerator = secretGenerator;
 }
 public static void RegisterConfigurationServices(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
 {
     factory.RegisterClientStore(options);
     factory.RegisterScopeStore(options);
 }
 public AuthorizationCodeStore(EntityFrameworkServiceOptions options, IOperationalDbContext context, IScopeStore scopeStore, IClientStore clientStore)
     : base(options, context, TokenType.AuthorizationCode, scopeStore, clientStore)
 {
 }
 public RefreshTokenStore(EntityFrameworkServiceOptions options, IOperationalDbContext context, IScopeStore scopeStore, IClientStore clientStore)
     : base(options, context, TokenType.RefreshToken, scopeStore, clientStore)
 {
 }
        public IdentityServerEfClientStore(EntityFrameworkServiceOptions options) 
            : this(options, new ClientIdGenerator(), new ClientSecretGenerator()) {

        }
 public TokenHandleStore(EntityFrameworkServiceOptions options, IOperationalDbContext context, IScopeStore scopeStore, IClientStore clientStore)
     : base(options, context, Entities.TokenType.TokenHandle, scopeStore, clientStore)
 {
 }