示例#1
0
        /// <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("factory");
            }
            if (cacheRegistration == null)
            {
                throw new ArgumentNullException("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));
            });
        }
        public static IdentityServerServiceFactory Create(
            List <InMemoryUser> users    = null,
            IEnumerable <Client> clients = null,
            IEnumerable <Scope> scopes   = null)
        {
            var factory = new IdentityServerServiceFactory();

            if (users != null)
            {
                factory.Register(Registration.RegisterSingleton <List <InMemoryUser> >(users));
                factory.UserService = Registration.RegisterType <IUserService>(typeof(InMemoryUserService));
            }

            if (clients != null)
            {
                factory.Register(Registration.RegisterSingleton <IEnumerable <Client> >(clients));
                factory.ClientStore = Registration.RegisterType <IClientStore>(typeof(InMemoryClientStore));
            }

            if (scopes != null)
            {
                factory.Register(Registration.RegisterSingleton <IEnumerable <Scope> >(scopes));
                factory.ScopeStore = Registration.RegisterType <IScopeStore>(typeof(InMemoryScopeStore));
            }

            return(factory);
        }
        /// <summary>
        /// Convenience method to create an instance of <see cref="IdentityServerServiceFactory" /> and
        /// configure it to use in-memory implementations of the <see cref="IUserService"/>, <see cref="IClientStore"/>, 
        /// and <see cref="IScopeStore"/>.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="clients">The clients.</param>
        /// <param name="scopes">The scopes.</param>
        /// <returns></returns>
        public static IdentityServerServiceFactory Create(
            List<InMemoryUser> users = null,
            IEnumerable<Client> clients = null,
            IEnumerable<Scope> scopes = null)
        {
            var factory = new IdentityServerServiceFactory();
            
            if (users != null)
            {
                factory.Register(new Registration<List<InMemoryUser>>(users));
                factory.UserService = new Registration<IUserService, InMemoryUserService>();
            }

            if (clients != null)
            {
                factory.Register(new Registration<IEnumerable<Client>>(clients));
                factory.ClientStore = new Registration<IClientStore>(typeof(InMemoryClientStore));
            }

            if (scopes != null)
            {
                factory.Register(new Registration<IEnumerable<Scope>>(scopes));
                factory.ScopeStore = new Registration<IScopeStore>(typeof(InMemoryScopeStore));
            }

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

            factory.ScopeStore = new Registration<IScopeStore, CustomScopeStore>();
            factory.ClientStore = new Registration<IClientStore, CustomClientStore>();

            factory.Register(new Registration<List<User>>(Users.Get()));
            factory.UserService = new Registration<IUserService, CustomUserService>();

            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>();
        }
示例#6
0
        /// <summary>
        /// Configures the default view service.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="options">The default view service options.</param>
        /// <exception cref="System.ArgumentNullException">
        /// factory
        /// or
        /// options
        /// </exception>
        /// <exception cref="System.InvalidOperationException">ViewService is already configured</exception>
        public static void ConfigureDefaultViewService(this IdentityServerServiceFactory factory,
                                                       DefaultViewServiceOptions options)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (factory.ViewService != null)
            {
                throw new InvalidOperationException("A ViewService is already configured");
            }

            factory.ViewService = new Registration <IViewService, DefaultViewService>();
            factory.Register(new Registration <DefaultViewServiceOptions>(options));

            if (options.ViewLoader == null)
            {
                options.ViewLoader = new Registration <IViewLoader, FileSystemWithEmbeddedFallbackViewLoader>();
            }

            if (options.CacheViews)
            {
                factory.Register(new Registration <IViewLoader>(options.ViewLoader, InnerRegistrationName));
                var cache = new ResourceCache();
                factory.Register(new Registration <IViewLoader>(
                                     resolver => new CachingLoader(cache, resolver.Resolve <IViewLoader>(InnerRegistrationName))));
            }
            else
            {
                factory.Register(options.ViewLoader);
            }
        }
        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>();
        }