//public static ClientValidator CreateClientValidator( // IClientStore clients = null, // IClientSecretValidator secretValidator = null) //{ // if (clients == null) // { // clients = new InMemoryClientStore(ClientValidationTestClients.Get()); // } // if (secretValidator == null) // { // secretValidator = new HashedClientSecretValidator(); // } // var owin = new OwinEnvironmentService(new OwinContext()); // return new ClientValidator(clients, secretValidator, owin); //} public static TokenRequestValidator CreateTokenRequestValidator( IdentityServerOptions options = null, IScopeStore scopes = null, IAuthorizationCodeStore authorizationCodeStore = null, IRefreshTokenStore refreshTokens = null, IUserService userService = null, IEnumerable<ICustomGrantValidator> customGrantValidators = null, ICustomRequestValidator customRequestValidator = null, ScopeValidator scopeValidator = null) { if (options == null) { options = TestIdentityServerOptions.Create(); } if (scopes == null) { scopes = new InMemoryScopeStore(TestScopes.Get()); } if (userService == null) { userService = new TestUserService(); } if (customRequestValidator == null) { customRequestValidator = new DefaultCustomRequestValidator(); } CustomGrantValidator aggregateCustomValidator; if (customGrantValidators == null) { aggregateCustomValidator = new CustomGrantValidator(new [] { new TestGrantValidator() }); } else { aggregateCustomValidator = new CustomGrantValidator(customGrantValidators); } if (refreshTokens == null) { refreshTokens = new InMemoryRefreshTokenStore(); } if (scopeValidator == null) { scopeValidator = new ScopeValidator(scopes); } return new TokenRequestValidator( options, authorizationCodeStore, refreshTokens, userService, aggregateCustomValidator, customRequestValidator, scopeValidator, new DefaultEventService()); }
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; }
public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory(); 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(); factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); var localizationService = new PortugueseBrazilLocalizationService(); factory.LocalizationService = new Registration<ILocalizationService>(localizationService); factory.ViewService = new Registration<IViewService, MvcViewService<LogonWorkflowController>>(); factory.Register(new Registration<HttpContext>(resolver => HttpContext.Current)); factory.Register(new Registration<HttpContextBase>(resolver => new HttpContextWrapper(resolver.Resolve<HttpContext>()))); factory.Register(new Registration<HttpRequestBase>(resolver => resolver.Resolve<HttpContextBase>().Request)); factory.Register(new Registration<HttpResponseBase>(resolver => resolver.Resolve<HttpContextBase>().Response)); factory.Register(new Registration<HttpServerUtilityBase>(resolver => resolver.Resolve<HttpContextBase>().Server)); factory.Register(new Registration<HttpSessionStateBase>(resolver => resolver.Resolve<HttpContextBase>().Session)); return factory; }
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() }); }
public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory(); var scopeStore = new InMemoryScopeStore(Scopes.Get()); factory.ScopeStore = new Registration<IScopeStore>(resolver => scopeStore); var clientStore = new InMemoryClientStore(Clients.Get()); factory.ClientStore = new Registration<IClientStore>(resolver => clientStore); return factory; }
public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory(); 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.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); return factory; }
public static IdentityServerServiceFactory Create() { var scopes = new InMemoryScopeStore(TestScopes.Get()); var clients = new InMemoryClientStore(TestClients.Get()); var fact = new IdentityServerServiceFactory { ScopeStore = new Registration<IScopeStore>((resolver) => scopes), ClientStore = new Registration<IClientStore>((resolver) => clients) }; return fact; }
public void AuthorizationCodePersists() { var subClaim = new Claim("sub", "*****@*****.**"); var emailClaim = new Claim("email", "*****@*****.**"); var code = new AuthorizationCode { Client = new Client { ClientId = "cid" }, RequestedScopes = new List<Scope> { new Scope { Description = "this is description", Enabled = true, Name = "sname", DisplayName = "This is Name!" } }, Subject = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { subClaim,emailClaim})) }; var clients = new List<Client> { new Client { ClientId = "cid", ClientName = "cname", Enabled = true, SlidingRefreshTokenLifetime = 100, AccessTokenType = AccessTokenType.Jwt, Flow = Flows.Implicit } }; var clientStore = new InMemoryClientStore(clients); var scopes = new List<Scope> { new Scope { Description = "sdescription", Name = "sname", Enabled = true, Emphasize = false, IncludeAllClaimsForUser = true, Required = false, Type = ScopeType.Identity } }; var scopeStore = new InMemoryScopeStore(scopes); var store = new RedisAuthorizationCodeStore(clientStore,scopeStore, RedisServer); store.StoreAsync("key1", code).Wait(); var result = store.GetAsync("key1").Result; Assert.Equal(code.SubjectId, result.SubjectId); Assert.Equal(code.ClientId, result.ClientId); }
public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory(); var scopes = Scopes.Get().ToList(); scopes.ForEach(s => s.IncludeAllClaimsForUser = true); var scopeStore = new InMemoryScopeStore(scopes); factory.ScopeStore = new Registration<IScopeStore>(scopeStore); var clientStore = new InMemoryClientStore(Clients.Get()); factory.ClientStore = new Registration<IClientStore>(clientStore); factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); return factory; }
public static IAppBuilder UseIdentityServer(this IAppBuilder app) { // uncomment to enable HSTS headers for the host // see: https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security //app.UseHsts(); app.Map("/core", coreApp => { //var factory = new IdentityServerServiceFactory() // .UseInMemoryUsers(Users.Get()) // .UseInMemoryClients(Clients.Get()) // .UseInMemoryScopes(Scopes.Get()); var factory = new IdentityServerServiceFactory(); 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.UseInMemoryUsers(Users.Get()); factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); factory.ConfigureClientStoreCache(); factory.ConfigureScopeStoreCache(); factory.ConfigureUserServiceCache(); var idsrvOptions = new IdentityServerOptions { Factory = factory, SigningCertificate = Cert.Load(), RequireSsl = false, AuthenticationOptions = new AuthenticationOptions { IdentityProviders = ConfigureIdentityProviders, }, }; coreApp.UseIdentityServer(idsrvOptions); }); return app; }
public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory(); var scopeStore = new InMemoryScopeStore(Scopes.Get()); factory.ScopeStore = new Registration<IScopeStore>(resolver => scopeStore); var clientStore = new InMemoryClientStore(Clients.Get()); factory.ClientStore = new Registration<IClientStore>(resolver => clientStore); factory.CorsPolicyService = new Registration<ICorsPolicyService>(new DefaultCorsPolicyService { AllowAll = true }); var viewOptions = new DefaultViewServiceOptions(); viewOptions.Stylesheets.Add("/Content/wts.css"); viewOptions.CacheViews = false; factory.ConfigureDefaultViewService(viewOptions); return factory; }
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 }; }
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; }
public static AuthorizeRequestValidator CreateAuthorizeRequestValidator( IdentityServerOptions options = null, IScopeStore scopes = null, IClientStore clients = null, IUserService users = null, ICustomRequestValidator customValidator = null, IRedirectUriValidator uriValidator = null, ScopeValidator scopeValidator = null, IDictionary<string, object> environment = null) { if (options == null) { options = TestIdentityServerOptions.Create(); } if (scopes == null) { scopes = new InMemoryScopeStore(TestScopes.Get()); } if (clients == null) { clients = new InMemoryClientStore(TestClients.Get()); } if (customValidator == null) { customValidator = new DefaultCustomRequestValidator(); } if (uriValidator == null) { uriValidator = new DefaultRedirectUriValidator(); } if (scopeValidator == null) { scopeValidator = new ScopeValidator(scopes); } var mockSessionCookie = new Mock<SessionCookie>((IOwinContext)null, (IdentityServerOptions)null); mockSessionCookie.CallBase = false; mockSessionCookie.Setup(x => x.GetSessionId()).Returns((string)null); return new AuthorizeRequestValidator(options, clients, customValidator, uriValidator, scopeValidator, mockSessionCookie.Object); }
public void RefreshTokenPersists() { var subClaim = new Claim("sub", "*****@*****.**"); var emailClaim = new Claim("email", "*****@*****.**"); var token = new RefreshToken { AccessToken = new Token { CreationTime = DateTimeOffset.Now, Audience = "aud", Claims = new List<Claim> { subClaim, emailClaim}, Client = new Client { ClientId = "cid", ClientName = "cname", Enabled = true, SlidingRefreshTokenLifetime = 100, AccessTokenType = AccessTokenType.Jwt, Flow = Flows.Implicit }, Issuer = "iss", Lifetime = 1234567, Type = Constants.TokenTypes.RefreshToken, Version = 1, }, CreationTime = DateTimeOffset.Now, Version = 1, LifeTime = 1234567, Subject = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { subClaim, emailClaim })) }; var clients = new List<Client> { new Client { ClientId = "cid", ClientName = "cname", Enabled = true, SlidingRefreshTokenLifetime = 100, AccessTokenType = AccessTokenType.Jwt, Flow = Flows.Implicit } }; var clientStore = new InMemoryClientStore(clients); var scopes = new List<Scope> { new Scope { Description = "sdescription", Name = "sname", Enabled = true, Emphasize = false, IncludeAllClaimsForUser = true, Required = false, Type = ScopeType.Identity } }; var scopeStore = new InMemoryScopeStore(scopes); var store = new RedisRefreshTokenStore(clientStore, scopeStore, RedisServer); store.StoreAsync("key2", token).Wait(); var result = store.GetAsync("key2").Result; Assert.Equal(token.SubjectId, result.SubjectId); Assert.Equal(token.ClientId, result.ClientId); }
public static IdentityServerServiceFactory UseInMemoryScopes(this IdentityServerServiceFactory factory, IEnumerable<Scope> scopes) { var scopeStore = new InMemoryScopeStore(scopes); factory.ScopeStore = new Registration<IScopeStore>(scopeStore); return factory; }