/// <summary> /// Configures the provided cache in the dependency injection system as a decorator for the scope store. /// </summary> /// <param name="factory">The factory.</param> /// <param name="cacheRegistration">The cache registration.</param> /// <exception cref="System.ArgumentNullException"> /// factory /// or /// cacheRegistration /// or /// ScopeStore needs to be configured on the factory /// </exception> public static void ConfigureScopeStoreCache(this IdentityServerServiceFactory factory, Registration <ICache <IEnumerable <Scope> > > cacheRegistration) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (cacheRegistration == null) { throw new ArgumentNullException(nameof(cacheRegistration)); } if (factory.ScopeStore == null) { throw new ArgumentNullException("ScopeStore needs to be configured on the factory"); } factory.Register(new Registration <ICache <IEnumerable <Scope> > >(cacheRegistration, CachingRegistrationName)); factory.Register(new Registration <IScopeStore>(factory.ScopeStore, InnerRegistrationName)); factory.ScopeStore = new Registration <IScopeStore>(resolver => { var inner = resolver.Resolve <IScopeStore>(InnerRegistrationName); var cache = resolver.Resolve <ICache <IEnumerable <Scope> > >(CachingRegistrationName); return(new CachingScopeStore(inner, cache)); }); }
/// <summary> /// Configures the provided cache in the dependency injection system as a decorator for the user service. /// </summary> /// <param name="factory">The factory.</param> /// <param name="cacheRegistration">The cache registration.</param> /// <exception cref="System.ArgumentNullException"> /// factory /// or /// cacheRegistration /// or /// UserService needs to be configured on the factory /// </exception> public static void ConfigureUserServiceCache(this IdentityServerServiceFactory factory, Registration <ICache <IEnumerable <Claim> > > cacheRegistration) { if (factory == null) { throw new ArgumentNullException("factory"); } if (cacheRegistration == null) { throw new ArgumentNullException("cacheRegistration"); } if (factory.UserService == null) { throw new ArgumentNullException("UserService needs to be configured on the factory"); } factory.Register(new Registration <ICache <IEnumerable <Claim> > >(cacheRegistration, CachingRegistrationName)); factory.Register(new Registration <IUserService>(factory.UserService, InnerRegistrationName)); factory.UserService = new Registration <IUserService>(resolver => { var inner = resolver.Resolve <IUserService>(InnerRegistrationName); var cache = resolver.Resolve <ICache <IEnumerable <Claim> > >(CachingRegistrationName); return(new CachingUserService(inner, cache)); }); }
private static void RegisterSessionFactory(IdentityServerServiceFactory factory, NhibernateServiceOptions serviceOptions) { if (factory.Registrations.All(r => r.DependencyType != typeof(ISessionFactory))) { factory.Register( new Registration <ISessionFactory>(serviceOptions.NhibernateSessionFactory)); factory.Register(new Registration <ISession>(c => c.Resolve <ISessionFactory>().OpenSession()) { Mode = RegistrationMode.InstancePerHttpRequest }); } }
/// <summary> /// Add Redis operational store services. /// Operational stores are: IAuthorizationCodeStore, ITokenHandleStore and IRefreshTokenStore. /// </summary> /// <param name="factory"></param> /// <param name="options">the ConfigurationOptions object.</param> /// <param name="keyPrefix">add a prefix to each key stored into Redis Cache, default is empty</param> public static void ConfigureOperationalRedisStoreServices(this IdentityServerServiceFactory factory, ConfigurationOptions options, string keyPrefix = "") { if (options == null) { throw new ArgumentNullException(nameof(options)); } factory.Register(new Registration <IConnectionMultiplexer>(ConnectionMultiplexer.Connect(options))); factory.Register(new Registration <IDatabase>(_ => _.Resolve <IConnectionMultiplexer>().GetDatabase())); factory.Register(new Registration <RedisKeyGenerator>(new RedisKeyGenerator(keyPrefix))); factory.AuthorizationCodeStore = new Registration <IAuthorizationCodeStore, AuthorizationCodeStore>(); factory.TokenHandleStore = new Registration <ITokenHandleStore, TokenHandleStore>(); factory.RefreshTokenStore = new Registration <IRefreshTokenStore, RefreshTokenStore>(); }
/// <summary> /// Add Redis operational store services. /// Operational stores are: IAuthorizationCodeStore, ITokenHandleStore and IRefreshTokenStore. /// </summary> /// <param name="factory"></param> /// <param name="redisStoreConnection">the connection string to Redis store</param> /// <param name="db">the db number</param> /// <param name="keyPrefix">add a prefix to each key stored into Redis Cache, default is empty</param> public static void ConfigureOperationalRedisStoreServices(this IdentityServerServiceFactory factory, string redisStoreConnection, int db = -1, string keyPrefix = "") { if (string.IsNullOrEmpty(redisStoreConnection)) { throw new ArgumentException(nameof(redisStoreConnection)); } factory.Register(new Registration <IConnectionMultiplexer>(ConnectionMultiplexer.Connect(redisStoreConnection))); factory.Register(new Registration <IDatabase>(_ => _.Resolve <IConnectionMultiplexer>().GetDatabase(db))); factory.Register(new Registration <RedisKeyGenerator>(new RedisKeyGenerator(keyPrefix))); factory.AuthorizationCodeStore = new Registration <IAuthorizationCodeStore, AuthorizationCodeStore>(); factory.TokenHandleStore = new Registration <ITokenHandleStore, TokenHandleStore>(); factory.RefreshTokenStore = new Registration <IRefreshTokenStore, RefreshTokenStore>(); }
/// <summary> /// Configures the factory to use in-memory users. /// </summary> /// <param name="factory">The factory.</param> /// <param name="users">The users.</param> /// <returns></returns> public static IdentityServerServiceFactory UseInMemoryUsers(this IdentityServerServiceFactory factory, List <InMemoryUser> users) { factory.Register(new Registration <List <InMemoryUser> >(users)); factory.UserService = new Registration <IUserService, InMemoryUserService>(); return(factory); }
/// <summary> /// Configures the factory to use in-memory scopes. /// </summary> /// <param name="factory">The factory.</param> /// <param name="scopes">The scopes.</param> /// <returns></returns> public static IdentityServerServiceFactory UseInMemoryScopes(this IdentityServerServiceFactory factory, IEnumerable <Scope> scopes) { factory.Register(new Registration <IEnumerable <Scope> >(scopes)); factory.ScopeStore = new Registration <IScopeStore>(typeof(InMemoryScopeStore)); return(factory); }
/// <summary> /// Configures the factory to use in-memory clients. /// </summary> /// <param name="factory">The factory.</param> /// <param name="clients">The clients.</param> /// <returns></returns> public static IdentityServerServiceFactory UseInMemoryClients(this IdentityServerServiceFactory factory, IEnumerable <Client> clients) { factory.Register(new Registration <IEnumerable <Client> >(clients)); factory.ClientStore = new Registration <IClientStore>(typeof(InMemoryClientStore)); factory.CorsPolicyService = new Registration <ICorsPolicyService>(new InMemoryCorsPolicyService(clients)); return(factory); }
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 static IdentityServerServiceFactory Configure(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions serviceOptions, string userBaseConnStr) { factory.RegisterOperationalServices(serviceOptions); factory.RegisterConfigurationServices(serviceOptions); //which one goes first? factory.Register(new Registration <Context>(resolver => new Context(userBaseConnStr))); factory.Register(new Registration <UserStore>()); factory.Register(new Registration <UserManager>()); factory.UserService = new Registration <IUserService, IdentityUserService>(); factory.CorsPolicyService = new Registration <ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); 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"); } if (options.SynchronousReads) { factory.Register(new Registration <EntityFrameworkServiceOptions>(options)); } factory.Register(new Registration <IScopeConfigurationDbContext>(resolver => new ScopeConfigurationDbContext(options.ConnectionString, options.Schema))); factory.ScopeStore = new Registration <IScopeStore, ScopeStore>(); }
public static void RegisterOperationalServices(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 <IOperationalDbContext>(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>(); }
public static void RegisterScopeStore(this IdentityServerServiceFactory factory, DapperServiceOptions options) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } factory.Register(new Registration <DapperServiceOptions>(options)); factory.ScopeStore = new Registration <IScopeStore, ScopeStore>(); }
public static void RegisterClientStore(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options) { if (factory == null) { throw new ArgumentNullException("factory"); } if (options == null) { throw new ArgumentNullException("options"); } factory.Register(new Registration <ClientConfigurationDbContext>(resolver => new ClientConfigurationDbContext(options.ConnectionString, options.Schema))); factory.ClientStore = new Registration <IClientStore, ClientStore>(); factory.CorsPolicyService = new ClientConfigurationCorsPolicyRegistration(options); }
public static void RegisterClientStore(this IdentityServerServiceFactory factory, DapperServiceOptions options) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } factory.Register(new Registration <DapperServiceOptions>(options)); factory.ClientStore = new Registration <IClientStore, ClientStore>(); factory.CorsPolicyService = new Registration <ICorsPolicyService, ClientConfigurationCorsPolicyService>(); }
public static void RegisterOperationalServices(this IdentityServerServiceFactory factory, DapperServiceOptions options) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } factory.Register(new Registration <DapperServiceOptions>(options)); factory.AuthorizationCodeStore = new Registration <IAuthorizationCodeStore, AuthorizationCodeStore>(); factory.TokenHandleStore = new Registration <ITokenHandleStore, TokenHandleStore>(); factory.ConsentStore = new Registration <IConsentStore, ConsentStore>(); factory.RefreshTokenStore = new Registration <IRefreshTokenStore, RefreshTokenStore>(); }
public static void ConfigureUserService(this IdentityServerServiceFactory factory) { factory.UserService = new Registration <IUserService, UserService <User, string> >(); factory.Register(new Registration <IUserStore <User, string> >(new InMemoryUserStore())); }