Esempio n. 1
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var svcFactory = new ServiceFactory(connString);

            svcFactory.ConfigureClients(Clients.Get());
            svcFactory.ConfigureScopes(Scopes.Get());

            var factory = new IdentityServerServiceFactory();

            var userService = new Thinktecture.IdentityServer.Core.Services.InMemory.InMemoryUserService(Users.Get());

            factory.UserService = Registration.RegisterFactory <IUserService>(() => userService);

            factory.ScopeStore  = Registration.RegisterFactory <IScopeStore>(svcFactory.CreateScopeStore);
            factory.ClientStore = Registration.RegisterFactory <IClientStore>(svcFactory.CreateClientStore);

            factory.AuthorizationCodeStore = Registration.RegisterFactory <IAuthorizationCodeStore>(svcFactory.CreateAuthorizationCodeStore);
            factory.TokenHandleStore       = Registration.RegisterFactory <ITokenHandleStore>(svcFactory.CreateTokenHandleStore);
            factory.ConsentService         = Registration.RegisterFactory <IConsentService>(svcFactory.CreateConsentService);
            factory.RefreshTokenStore      = Registration.RegisterFactory <IRefreshTokenStore>(svcFactory.CreateRefreshTokenStore);

            // Remove expired tokens every 5 minutes
            ExpiredTokenCollector.Start(connString, 5);

            return(factory);
        }
        public static IdentityServerServiceFactory Create(
            string connectionStringName, string issuerUri, string siteName, string publicHostAddress = "")
        {
            var users = new[]
            {
                new InMemoryUser {
                    Subject = "818727", Username = "******", Password = "******",
                    Claims  = new []
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Alice"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**")
                    }
                },
                new InMemoryUser {
                    Subject = "88421113", Username = "******", Password = "******",
                    Claims  = new []
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**")
                    }
                }
            };

            var settings = new LocalTestCoreSettings(issuerUri, siteName, publicHostAddress);

            var userSvc = new InMemoryUserService(users);

            var efServiceFactory = new Core.EntityFramework.ServiceFactory("name=" + connectionStringName);

            efServiceFactory.ConfigureClients(LocalTestClients.Get());
            efServiceFactory.ConfigureScopes(LocalTestScopes.Get());

            // if we're going to use a database to store our tokens, we'll need to clean up at some point
            ExpiredTokenCollector.Start("name=" + connectionStringName, 5);

            var fact = new IdentityServerServiceFactory
            {
                CoreSettings           = Registration.RegisterFactory <CoreSettings>(() => settings),
                UserService            = Registration.RegisterFactory <IUserService>(() => userSvc),
                ScopeService           = Registration.RegisterFactory <IScopeService>(efServiceFactory.CreateScopeService),
                ClientService          = Registration.RegisterFactory <IClientService>(efServiceFactory.CreateClientService),
                ConsentService         = Registration.RegisterFactory <IConsentService>(efServiceFactory.CreateConsentService),
                AuthorizationCodeStore = Registration.RegisterFactory <IAuthorizationCodeStore>(efServiceFactory.CreateAuthorizationCodeStore),
                TokenHandleStore       = Registration.RegisterFactory <ITokenHandleStore>(efServiceFactory.CreateTokenHandleStore),
                RefreshTokenStore      = Registration.RegisterFactory <IRefreshTokenStore>(efServiceFactory.CreateRefreshTokenStore)
            };

            return(fact);
        }