示例#1
0
        public void Configuration(IAppBuilder app)
        {
            // tracing
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Trace()
                         .CreateLogger();

            // in-memory datenhaltung für users, scopes, clients und CORS policys
            var users   = new InMemoryUserService(Users.Get());
            var scopes  = new InMemoryScopeStore(Scopes.Get());
            var clients = new InMemoryClientStore(Clients.Get());
            var cors    = new InMemoryCorsPolicyService(Clients.Get());

            // konfigurieren der factory
            var factory = new IdentityServerServiceFactory();

            factory.UserService       = new Registration <IUserService>(users);
            factory.ScopeStore        = new Registration <IScopeStore>(scopes);
            factory.ClientStore       = new Registration <IClientStore>(clients);
            factory.CorsPolicyService = new Registration <ICorsPolicyService>(cors);

            // identityserver3 middleware einbinden
            app.UseIdentityServer(new IdentityServerOptions
            {
                Factory  = factory,
                SiteName = "DotNetPro IdentityServer",

                SigningCertificate = Certificate.Get()
            });
        }
示例#2
0
        public static IdentityServerServiceFactory Create(
            IEnumerable <InMemoryUser> users = null,
            IEnumerable <Client> clients     = null,
            IEnumerable <Scope> scopes       = null)
        {
            var factory = new IdentityServerServiceFactory();

            if (users != null)
            {
                var userService = new InMemoryUserService(users);
                factory.UserService = Registration.RegisterFactory <IUserService>(() => userService);
            }

            if (clients != null)
            {
                var clientStore = new InMemoryClientStore(clients);
                factory.ClientStore = Registration.RegisterFactory <IClientStore>(() => clientStore);
            }

            if (scopes != null)
            {
                var scopeStore = new InMemoryScopeStore(scopes);
                factory.ScopeStore = Registration.RegisterFactory <IScopeStore>(() => scopeStore);
            }

            return(factory);
        }
示例#3
0
        public void Configuration(IAppBuilder app)
        {
            var scope  = new InMemoryScopeStore(Scopes.Get());
            var client = new InMemoryClientStore(Clients.Get());
            var users  = new InMemoryUserService(Users.Get());

            var factory = new IdentityServerServiceFactory
            {
                UserService = new Registration <IUserService>(users),
                ScopeStore  = new Registration <IScopeStore>(scope),
                ClientStore = new Registration <IClientStore>(client)
            };

            var options = new IdentityServerOptions
            {
                RequireSsl            = false,
                Factory               = factory,
                SiteName              = "My Test Provider",
                AuthenticationOptions = new AuthenticationOptions
                {
                    IdentityProviders = ConfigureIpds
                },
                SigningCertificate = X509.LocalMachine.My.SubjectDistinguishedName.Find("CN=testcert", false).First()
            };

            app.UseIdentityServer(options);

            app.UseWelcomePage();
        }
 public static InMemoryUserService Get()
 {
     if (_service == null)
     {
         _service = new InMemoryUserService(Users.Get());
     }
     return(_service);
 }
        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);
        }
        public static IdentityServerServiceFactory Create(
            string issuerUri, string siteName, string publicHostAddress = "")
        {
            var settings = new LocalTestCoreSettings(issuerUri, siteName, publicHostAddress);

            var codeStore  = new InMemoryAuthorizationCodeStore();
            var tokenStore = new InMemoryTokenHandleStore();
            var consent    = new InMemoryConsentService();
            var scopes     = new InMemoryScopeService(LocalTestScopes.Get());
            var clients    = new InMemoryClientService(LocalTestClients.Get());
            var logger     = new TraceLogger();

            var users = new InMemoryUser[]
            {
                new InMemoryUser {
                    Subject = "alice", Username = "******", Password = "******",
                    Claims  = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Alice"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
                new InMemoryUser {
                    Subject = "bob", Username = "******", Password = "******",
                    Claims  = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
            };
            var userSvc = new InMemoryUserService(users);

            var fact = new IdentityServerServiceFactory
            {
                Logger                 = () => logger,
                UserService            = () => userSvc,
                AuthorizationCodeStore = () => codeStore,
                TokenHandleStore       = () => tokenStore,
                CoreSettings           = () => settings,
                ConsentService         = () => consent,
                ScopeService           = () => scopes,
                ClientService          = () => clients
            };

            return(fact);
        }
示例#7
0
        public KnownUserService(string adminUsername, string adminPassword)
        {
            if (string.IsNullOrWhiteSpace(adminUsername))
            {
                throw new ArgumentNullException("adminUsername");
            }

            if (string.IsNullOrWhiteSpace(adminPassword))
            {
                throw new ArgumentNullException("adminPassword");
            }

            this.inMemoryUserService =
                new InMemoryUserService(this.GetUsers(adminUsername, adminPassword).ToList());
        }
        public static IdentityServerServiceFactory Create()
        {
            var factory = new IdentityServerServiceFactory();

            var scopeStore = new InMemoryScopeStore(Scopes.ScopesRepository.GetAll());

            factory.ScopeStore = new Registration <IScopeStore>(resolver => scopeStore);

            var clientStore = new InMemoryClientStore(Clients.ClientsRepository.GetAll());

            factory.ClientStore = new Registration <IClientStore>(resolver => clientStore);

            var usersStore = new InMemoryUserService(new List <InMemoryUser>());

            factory.UserService = new Registration <IUserService>(resolver => usersStore);

            return(factory);
        }
示例#9
0
        public IdentityServerHost()
        {
            var clientStore = new InMemoryClientStore(Clients);
            var scopeStore  = new InMemoryScopeStore(Scopes);
            var userService = new InMemoryUserService(Users);

            var factory = new IdentityServerServiceFactory
            {
                ScopeStore  = new Registration <IScopeStore>(scopeStore),
                ClientStore = new Registration <IClientStore>(clientStore),
                UserService = new Registration <IUserService>(userService),
            };

            Options = new IdentityServerOptions
            {
                Factory            = factory,
                DataProtector      = new NoDataProtector(),
                SiteName           = "IdentityServer3 Host",
                SigningCertificate = SigningCertificate
            };
        }
示例#10
0
        public static IdentityServerServiceFactory Create(
            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 scopes   = new InMemoryScopeService(LocalTestScopes.Get());
            var clients  = new InMemoryClientService(LocalTestClients.Get());
            var userSvc  = new InMemoryUserService(users);

            var fact = new IdentityServerServiceFactory
            {
                UserService   = Registration.RegisterFactory <IUserService>(() => userSvc),
                CoreSettings  = Registration.RegisterFactory <CoreSettings>(() => settings),
                ScopeService  = Registration.RegisterFactory <IScopeService>(() => scopes),
                ClientService = Registration.RegisterFactory <IClientService>(() => clients)
            };

            return(fact);
        }