public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; var defaultViewServiceOptions = new DefaultViewServiceOptions(); defaultViewServiceOptions.CacheViews = false; var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()); // .UseInMemoryUsers(Users.Get()); idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); idServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions); // use custom UserService var customUserService = new CustomUserService(); idServerServiceFactory.UserService = new Registration <IUserService>(resolver => customUserService); var options = new IdentityServerOptions { Factory = idServerServiceFactory, SiteName = "TripCompany Security Token Service", SigningCertificate = LoadCertificate(), IssuerUri = TripGallery.Constants.TripGalleryIssuerUri, PublicOrigin = TripGallery.Constants.TripGallerySTSOrigin, AuthenticationOptions = new AuthenticationOptions() { EnablePostSignOutAutoRedirect = true, LoginPageLinks = new List <LoginPageLink>() { new LoginPageLink() { Type = "createaccount", Text = "Create a new account", Href = "~/createuseraccount" } }, IdentityProviders = ConfigureAdditionalIdProviders }, CspOptions = new CspOptions() { Enabled = false // once available, leave Enabled at true and use: // FrameSrc = "https://localhost:44318 https://localhost:44316" // or // FrameSrc = "*" for all URI's. } }; idsrvApp.UseIdentityServer(options); }); }
public void Configuration(IAppBuilder app) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Trace() .CreateLogger(); app.Map("/core", coreApp => { var factory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()); var userSrv = new CustomUserService(); factory.UserService = new Registration <IUserService>(resolver => userSrv); factory.CorsPolicyService = new Registration <ICorsPolicyService>( new DefaultCorsPolicyService { AllowAll = true } ); var options = new IdentityServerOptions { SiteName = "Example Identity Server", SigningCertificate = Cert.Load(), RequireSsl = true, Factory = factory, EventsOptions = new EventsOptions { RaiseSuccessEvents = true, RaiseErrorEvents = true, RaiseFailureEvents = true, RaiseInformationEvents = true }, AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions { EnablePostSignOutAutoRedirect = true } }; coreApp.UseIdentityServer(options); }); }
protected override bool OnAuthorizeUser(string username, string password, HttpActionContext actionContext) { IUserService provider = new CustomUserService(); if (provider != null) { var userId = provider.Authenticate(username, password); if (userId > 0) { var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity; if (basicAuthenticationIdentity != null) { basicAuthenticationIdentity.UserId = userId; } return(true); } } return(false); }
public void Configuration(IAppBuilder app) { // enable CORS var corsPolicyService = new DefaultCorsPolicyService() { AllowAll = true }; /*Now let's ensure we startup identity server with the correct configuration so it uses what we just added. */ /*Here we are mapping to a certain URI\identity with app.map we can map that \identity URI to the identity server app and configure it. To startup identity server, we can use a factor and pass that into the options used for configuring identity server. When configuring this factory, we can state where the clients, scopes, and users come from. */ app.Map("/identity", idsrvApp => { // here we are configuring a security token service (STS) var idServerServiceFactory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()); //.UseInMemoryUsers(Users.Get()); // we can now start using our CustomUserService(). // do not cache the views var defaultViewServiceOptions = new DefaultViewServiceOptions(); defaultViewServiceOptions.CacheViews = false; // Register CORS idServerServiceFactory.CorsPolicyService = new Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService); // use our custom UserService var customUserService = new CustomUserService(); idServerServiceFactory.UserService = new Registration <IUserService>(resolver => customUserService); // create an identityserver option instance var options = new IdentityServerOptions { Factory = idServerServiceFactory, SiteName = "TripCompany Security Token Service", IssuerUri = TripGallery.Constants.TripGalleryIssuerUri, PublicOrigin = TripGallery.Constants.TripGallerySTSOrigin, SigningCertificate = LoadCertificate(), AuthenticationOptions = new AuthenticationOptions() { EnablePostSignOutAutoRedirect = true, //enable single-sign-out //PostSignOutAutoRedirectDelay = 2 // 2 seconds delay LoginPageLinks = new List <LoginPageLink>() // link for registration { new LoginPageLink() { Type = "createaccount", Text = "Create a new account", Href = "~/createuseraccount" } }, IdentityProviders = ConfigureAdditionalIdProviders }, CspOptions = new CspOptions() { Enabled = false // once available, leave Enabled at true and use: // FrameSrc = "https://localhost:44318 https://localhost:44316" // or // FrameSrc = "*" for all URI's. } }; idsrvApp.UseIdentityServer(options); }); }