public virtual void Configure(IAppBuilder owinApp) { if (owinApp == null) { throw new ArgumentNullException(nameof(owinApp)); } owinApp.Map("/core", coreApp => { LogProvider.SetCurrentLogProvider(DependencyManager.Resolve <ILogProvider>()); IdentityServerServiceFactory factory = new IdentityServerServiceFactory() .UseInMemoryClients(DependencyManager.Resolve <IOAuthClientsProvider>().GetClients().ToArray()) .UseInMemoryScopes(ScopesProvider.GetScopes()); IUserService ResolveUserService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); IUserService userService = owinContext.GetDependencyResolver().Resolve <IUserService>(); return(userService); } factory.UserService = new Registration <IUserService>(ResolveUserService); IEventService ResolveEventService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); if (owinContext.TryGetDependencyResolver(out Core.Contracts.IDependencyResolver? dependencyResolver)) { IRequestInformationProvider requestInformationProvider = dependencyResolver.Resolve <IRequestInformationProvider>(); if (IPAddress.TryParse(requestInformationProvider.ClientIp, out IPAddress _)) { owinContext.Request.RemoteIpAddress = requestInformationProvider.ClientIp; } else { owinContext.Request.RemoteIpAddress = "::1"; } return(dependencyResolver.Resolve <IEventService>()); } else { return(new FakeEventService { }); } }
public virtual void Configure(IAppBuilder owinApp) { if (owinApp == null) { throw new ArgumentNullException(nameof(owinApp)); } owinApp.Map("/core", coreApp => { LogProvider.SetCurrentLogProvider(DependencyManager.Resolve <ILogProvider>()); IdentityServerServiceFactory factory = new IdentityServerServiceFactory() .UseInMemoryClients(DependencyManager.Resolve <IOAuthClientsProvider>().GetClients().ToArray()) .UseInMemoryScopes(ScopesProvider.GetScopes()); IUserService ResolveUserService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); IUserService userService = owinContext.GetDependencyResolver().Resolve <IUserService>(); return(userService); } factory.UserService = new Registration <IUserService>(ResolveUserService); IEventService ResolveEventService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); if (owinContext.TryGetDependencyResolver(out Core.Contracts.IDependencyResolver dependencyResolver)) { IRequestInformationProvider requestInformationProvider = dependencyResolver.Resolve <IRequestInformationProvider>(); owinEnv.Environment["server.RemoteIpAddress"] = requestInformationProvider.ClientIp ?? "::1"; // some test hosts won't provide remote ip address request feature and idSrv requires it in event sevice decorator. return(dependencyResolver.Resolve <IEventService>()); } else { return(new FakeEventService { }); } }
public virtual void Configure(IAppBuilder owinApp) { if (owinApp == null) { throw new ArgumentNullException(nameof(owinApp)); } owinApp.Map("/core", coreApp => { LogProvider.SetCurrentLogProvider(DependencyManager.Resolve <ILogProvider>()); IdentityServerServiceFactory factory = new IdentityServerServiceFactory() .UseInMemoryClients(DependencyManager.Resolve <IOAuthClientsProvider>().GetClients().ToArray()) .UseInMemoryScopes(ScopesProvider.GetScopes()); IUserService ResolveUserService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); IUserService userService = owinContext.GetDependencyResolver().Resolve <IUserService>(); if (userService is UserService bitUserService) { bitUserService.CurrentCancellationToken = owinContext.Request.CallCancelled; } return(userService); } factory.UserService = new Registration <IUserService>(ResolveUserService); factory.EventService = new Registration <IEventService>(EventService); IViewService ResolveViewService(IdentityServer3.Core.Services.IDependencyResolver resolver) { OwinEnvironmentService owinEnv = resolver.Resolve <OwinEnvironmentService>(); IOwinContext owinContext = new OwinContext(owinEnv.Environment); return(owinContext.GetDependencyResolver().Resolve <IViewService>()); } factory.ViewService = new Registration <IViewService>(ResolveViewService); factory.RedirectUriValidator = new Registration <IRedirectUriValidator>(RedirectUriValidator); bool requireSslConfigValue = AppEnvironment.GetConfig("RequireSsl", defaultValueOnNotFound: false); string identityServerSiteName = AppEnvironment.GetConfig("IdentityServerSiteName", $"{AppEnvironment.AppInfo.Name} Identity Server"); IdentityServerOptions identityServerOptions = new IdentityServerOptions { SiteName = identityServerSiteName, SigningCertificate = AppCertificatesProvider.GetSingleSignOnCertificate(), Factory = factory, RequireSsl = requireSslConfigValue, EnableWelcomePage = AppEnvironment.DebugMode == true, IssuerUri = AppEnvironment.GetSsoIssuerName(), CspOptions = new CspOptions { // Content security policy Enabled = false }, Endpoints = new EndpointOptions { EnableAccessTokenValidationEndpoint = true, EnableAuthorizeEndpoint = true, EnableCheckSessionEndpoint = true, EnableClientPermissionsEndpoint = true, EnableCspReportEndpoint = true, EnableDiscoveryEndpoint = true, EnableEndSessionEndpoint = true, EnableIdentityTokenValidationEndpoint = true, EnableIntrospectionEndpoint = true, EnableTokenEndpoint = true, EnableTokenRevocationEndpoint = true, EnableUserInfoEndpoint = true }, EventsOptions = new EventsOptions { RaiseErrorEvents = true, RaiseFailureEvents = true }, AuthenticationOptions = new AuthenticationOptions { IdentityProviders = ConfigureIdentityProviders } }; foreach (IIdentityServerOptionsCustomizer customizer in Customizers) { customizer.Customize(identityServerOptions); } coreApp.UseIdentityServer(identityServerOptions); }); }
public virtual void Configure(IAppBuilder owinApp) { if (owinApp == null) { throw new ArgumentNullException(nameof(owinApp)); } owinApp.Map("/core", coreApp => { LogProvider.SetCurrentLogProvider(DependencyManager.Resolve <ILogProvider>()); AppEnvironment activeAppEnvironment = AppEnvironmentProvider.GetActiveAppEnvironment(); IdentityServerServiceFactory factory = new IdentityServerServiceFactory() .UseInMemoryClients(DependencyManager.Resolve <IClientProvider>().GetClients().ToArray()) .UseInMemoryScopes(ScopesProvider.GetScopes()); factory.UserService = new Registration <IUserService>(DependencyManager.Resolve <IUserService>()); factory.EventService = new Registration <IEventService>(EventService); factory.ViewService = new Registration <IViewService>(DependencyManager.Resolve <IViewService>()); factory.RedirectUriValidator = new Registration <IRedirectUriValidator>(RedirectUriValidator); bool requireSslConfigValue = activeAppEnvironment.GetConfig("RequireSsl", defaultValueOnNotFound: false); string identityServerSiteName = activeAppEnvironment.GetConfig("IdentityServerSiteName", $"{activeAppEnvironment.AppInfo.Name} Identity Server"); IdentityServerOptions identityServerOptions = new IdentityServerOptions { SiteName = identityServerSiteName, SigningCertificate = CertificateProvider.GetSingleSignOnCertificate(), Factory = factory, RequireSsl = requireSslConfigValue, EnableWelcomePage = activeAppEnvironment.DebugMode == true, IssuerUri = activeAppEnvironment.GetSsoIssuerName(), CspOptions = new CspOptions { // Content security policy Enabled = false }, Endpoints = new EndpointOptions { EnableAccessTokenValidationEndpoint = true, EnableAuthorizeEndpoint = true, EnableCheckSessionEndpoint = true, EnableClientPermissionsEndpoint = true, EnableCspReportEndpoint = true, EnableDiscoveryEndpoint = true, EnableEndSessionEndpoint = true, EnableIdentityTokenValidationEndpoint = true, EnableIntrospectionEndpoint = true, EnableTokenEndpoint = true, EnableTokenRevocationEndpoint = true, EnableUserInfoEndpoint = true }, EventsOptions = new EventsOptions { RaiseErrorEvents = true, RaiseFailureEvents = true } }; coreApp.UseIdentityServer(identityServerOptions); }); }