public static AuthorizeRequestValidator CreateAuthorizeValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes = null,
            IClientStore clients = null,
            IUserService users = null,
            ICustomRequestValidator customValidator = null)
        {
            if (options == null)
            {
                options = Thinktecture.IdentityServer.Tests.TestIdentityServerOptions.Create();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeStore(TestScopes.Get());
            }

            if (clients == null)
            {
                clients = new InMemoryClientStore(TestClients.Get());
            }

            if (customValidator == null)
            {
                customValidator = new DefaultCustomRequestValidator();
            }

            return new AuthorizeRequestValidator(options, scopes, clients, customValidator);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserInfoEndpointController"/> class.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="tokenValidator">The token validator.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="tokenUsageValidator">The token usage validator.</param>
 public UserInfoEndpointController(IdentityServerOptions options, TokenValidator tokenValidator, UserInfoResponseGenerator generator, BearerTokenUsageValidator tokenUsageValidator)
 {
     _tokenValidator = tokenValidator;
     _generator = generator;
     _options = options;
     _tokenUsageValidator = tokenUsageValidator;
 }
 public AuthenticationController(
     OwinEnvironmentService owin,
     IViewService viewService, 
     IUserService userService, 
     IdentityServerOptions idSvrOptions, 
     IClientStore clientStore, 
     IEventService eventService,
     ILocalizationService localizationService,
     SessionCookie sessionCookie, 
     MessageCookie<SignInMessage> signInMessageCookie,
     MessageCookie<SignOutMessage> signOutMessageCookie,
     LastUserNameCookie lastUsernameCookie,
     AntiForgeryToken antiForgeryToken)
 {
     this.context = new OwinContext(owin.Environment);
     this.viewService = viewService;
     this.userService = userService;
     this.options = idSvrOptions;
     this.clientStore = clientStore;
     this.eventService = eventService;
     this.localizationService = localizationService;
     this.sessionCookie = sessionCookie;
     this.signInMessageCookie = signInMessageCookie;
     this.signOutMessageCookie = signOutMessageCookie;
     this.lastUsernameCookie = lastUsernameCookie;
     this.antiForgeryToken = antiForgeryToken;
 }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/admin", adminApp =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.ConfigureSimpleIdentityManagerService("AspId");

                adminApp.UseIdentityManager(new IdentityManagerOptions()
                {
                    Factory = factory
                });
            });
            app.Map("/core", core =>
            {
                var idSvrFactory = Factory.Configure();
                idSvrFactory.ConfigureUserService("AspId");

                var options = new IdentityServerOptions
                {
                    SiteName = "Thinktecture IdentityServer3 - AspNetIdentity 2FA",
                    SigningCertificate = Certificate.Get(),
                    Factory = idSvrFactory,
                };

                core.UseIdentityServer(options);
            });
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/admin", adminApp =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.ConfigureSimpleIdentityManagerService("AspId");
                //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK");

                adminApp.UseIdentityManager(new IdentityManagerOptions()
                {
                    Factory = factory
                });
            });

            var idSvrFactory = Factory.Configure();
            idSvrFactory.ConfigureUserService("AspId");
            //idSvrFactory.ConfigureCustomUserService("AspId_CustomPK");

            var options = new IdentityServerOptions
            {
                SiteName = "Thinktecture IdentityServer3 - UserService-AspNetIdentity",
                SigningCertificate = Certificate.Get(),
                Factory = idSvrFactory,
                CorsPolicy = CorsPolicy.AllowAll,
                AuthenticationOptions = new AuthenticationOptions
                {
                    IdentityProviders = ConfigureAdditionalIdentityProviders,
                }
            };

            app.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            app.Map("/idsrv", idSrvApp =>
            {
                var factory = InMemoryFactory.Create(
                    users: Users.Get(),
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                factory.ConfigureClientStoreCache();
                factory.ConfigureScopeStoreCache();
                factory.ConfigureUserServiceCache();

                var idsrvOptions = new IdentityServerOptions
                {
                    SiteName = "ACME Identity Server",
                    IssuerUri = "https://idsrv.acme.com",
                    Factory = factory,
                    SigningCertificate = Cert.Load(),

                    CorsPolicy = CorsPolicy.AllowAll,
                };

                idSrvApp.UseIdentityServer(idsrvOptions);
            });
        }
        public void Configuration(IAppBuilder app)
        {
            var connString = "AspId";
            //var connString = "CustomAspId";

            app.Map("/admin", adminApp =>
            {
                var factory = new AspNetIdentityIdentityManagerFactory(connString);
                adminApp.UseIdentityManager(new IdentityManagerConfiguration()
                {
                    IdentityManagerFactory = factory.Create
                });
            });

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName = "Thinktecture IdentityServer v3 - UserService-AspNetIdentity",
                PublicHostName = "http://localhost:3333",

                SigningCertificate = Certificate.Get(),
                Factory = Factory.Configure(connString),
                CorsPolicy = CorsPolicy.AllowAll
            };

            app.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    users:   Users.Get(),
                    clients: Clients.Get(),
                    scopes:  Scopes.Get());

                var viewOptions = new DefaultViewServiceOptions();
                viewOptions.Stylesheets.Add("/Content/Site.css");
                viewOptions.CacheViews = false;
                factory.ConfigureDefaultViewService(viewOptions);

                var options = new IdentityServerOptions
                {
                    SiteName = "Thinktecture IdentityServer3 - Configuring DefaultViewService",

                    SigningCertificate = Certificate.Get(),
                    Factory = factory,
                    CorsPolicy = CorsPolicy.AllowAll,

                    AuthenticationOptions = new AuthenticationOptions{
                        IdentityProviders = ConfigureAdditionalIdentityProviders,
                    }
                };

                coreApp.UseIdentityServer(options);
            });
        }
 public DefaultTokenService(IdentityServerOptions options, IClaimsProvider claimsProvider, ITokenHandleStore tokenHandles, ITokenSigningService signingService)
 {
     _options = options;
     _claimsProvider = claimsProvider;
     _tokenHandles = tokenHandles;
     _signingService = signingService;
 }
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    users : Users.Get(),
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                factory.ViewService = new Registration<IViewService>(typeof(CustomViewService));
                //factory.UserService = new Registration<IUserService, UserService>();

                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://idsrv3.com",
                    SiteName = "Thinktecture IdentityServer3 - CustomViewService",

                    SigningCertificate = Certificate.Get(),
                    Factory = factory,
                    CorsPolicy = CorsPolicy.AllowAll,
                    AuthenticationOptions = new AuthenticationOptions {
                        IdentityProviders = ConfigureAdditionalIdentityProviders,
                    }
                };

                coreApp.UseIdentityServer(options);
            });
        }
 public TokenValidator(IdentityServerOptions options, IClientStore clients, ITokenHandleStore tokenHandles, ICustomTokenValidator customValidator)
 {
     _options = options;
     _clients = clients;
     _tokenHandles = tokenHandles;
     _customValidator = customValidator;
 }
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            // 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 = Factory.Create();

                    var idsrvOptions = new IdentityServerOptions
                    {
                        IssuerUri = "https://idsrv3.com",
                        SiteName = "Thinktecture IdentityServer v3 - preview 1",
                        SigningCertificate = Cert.Load(),
                        CspReportEndpoint = EndpointSettings.Enabled,
                        AccessTokenValidationEndpoint = EndpointSettings.Enabled,
                        PublicHostName = "http://localhost:3333",
                        Factory = factory,
                        AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,
                        CorsPolicy = CorsPolicy.AllowAll
                    };
                    coreApp.UseIdentityServer(idsrvOptions);
                });
        }
 public AccessTokenValidationController(TokenValidator validator, IdentityServerOptions options, ILocalizationService localizationService, IEventService events)
 {
     _validator = validator;
     _options = options;
     _localizationService = localizationService;
     _events = events;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TokenEndpointController"/> class.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="requestValidator">The request validator.</param>
 /// <param name="clientValidator">The client validator.</param>
 /// <param name="generator">The generator.</param>
 public TokenEndpointController(IdentityServerOptions options, TokenRequestValidator requestValidator, ClientValidator clientValidator, TokenResponseGenerator generator)
 {
     _requestValidator = requestValidator;
     _clientValidator = clientValidator;
     _generator = generator;
     _options = options;
 }
        public static string GetRedirectUrl(SignInMessage message, IDictionary<string, object> env, IdentityServerOptions options)
        {
            var result = new LoginResult(message, env, options);
            var response = result.Execute();

            return response.Headers.Location.AbsoluteUri;
        }
        public void Configuration(IAppBuilder appBuilder)
        {
            var factory = InMemoryFactory.Create(
                users:   Users.Get(), 
                clients: Clients.Get(), 
                scopes:  Scopes.Get());

            factory.ClaimsProvider = 
                new Registration<IClaimsProvider>(typeof(CustomClaimsProvider));
            factory.UserService = 
                new Registration<IUserService>(typeof(CustomUserService));
            factory.CustomGrantValidator = 
                new Registration<ICustomGrantValidator>(typeof(CustomGrantValidator));

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName = "Thinktecture IdentityServer3 (CustomGrants)",
                RequireSsl = false,

                SigningCertificate = Certificate.Get(),
                Factory = factory,
            };

            appBuilder.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder app)
        {
            var connectionString = "MembershipReboot";

            app.Map("/admin", adminApp =>
            {
                var factory = new IdentityManagerServiceFactory();
                factory.Configure(connectionString);

                adminApp.UseIdentityManager(new IdentityManagerOptions()
                {
                    Factory = factory
                });
            });


            var idSvrFactory = Factory.Configure();
            idSvrFactory.ConfigureCustomUserService(connectionString);

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName = "Thinktecture IdentityServer3 - UserService-MembershipReboot",
                
                SigningCertificate = Certificate.Get(),
                Factory = idSvrFactory,
                CorsPolicy = CorsPolicy.AllowAll,
                AuthenticationOptions = new AuthenticationOptions{
                    IdentityProviders = ConfigureAdditionalIdentityProviders,
                }
            };

            app.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                //var userService = new ExternalRegistrationUserService();
                //var userService = new EulaAtLoginUserService();
                var userService = new LocalRegistrationUserService();
                factory.UserService = Registration.RegisterFactory<IUserService>(() => userService);

                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://idsrv3.com",
                    SiteName = "Thinktecture IdentityServer v3 - CustomUserService",
                    PublicHostName = "http://localhost:3333",
                    SigningCertificate = Certificate.Get(),
                    Factory = factory,
                    AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,
                    CorsPolicy = CorsPolicy.AllowAll,
                    AuthenticationOptions = new AuthenticationOptions {
                        LoginPageLinks = new LoginPageLink[] { 
                            new LoginPageLink{
                                Text = "Register",
                                Href = "localregistration"
                            }
                        }
                    }
                };

                coreApp.UseIdentityServer(options);
            });
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    users : Users.Get(),
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                var embeddedViewServiceConfig = new EmbeddedAssetsViewServiceConfiguration();
                embeddedViewServiceConfig.Stylesheets.Add("/Content/Site.css");

                factory.Register(Registration.RegisterSingleton(embeddedViewServiceConfig));

                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://idsrv3.com",
                    SiteName = "Thinktecture IdentityServer v3 - UserService-CustomWorkflows",
                    PublicHostName = "http://localhost:3333",
                    SigningCertificate = Certificate.Get(),
                    Factory = factory,
                    AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,
                    CorsPolicy = CorsPolicy.AllowAll,
                };

                coreApp.UseIdentityServer(options);
            });
        }
        public void Configuration(IAppBuilder appBuilder)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole(
                    outputTemplate: "{Timestamp:HH:mm} [{Level}] ({Name}) {NewLine} {Message}{NewLine}{Exception}")
                .CreateLogger();

            LogProvider.SetCurrentLogProvider(new SerilogLogProvider());

            var factory = InMemoryFactory.Create(
                users:   Users.Get(), 
                clients: Clients.Get(), 
                scopes:  Scopes.Get());

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName = "Thinktecture IdentityServer3 (self host)",

                SigningCertificate = Certificate.Get(),
                Factory = factory,
            };

            appBuilder.UseIdentityServer(options);
        }
        public static IAppBuilder UseIdentityServerViewLocalization(this IAppBuilder app, 
            IdentityServerOptions identityServerOptions, 
            IdentityServerViewLocalizationOptions options)
        {
            if (identityServerOptions == null) throw new ArgumentNullException("identityServerOptions");
            if (options == null) throw new ArgumentNullException("options");

            var factory = identityServerOptions.Factory;
            if (factory == null) throw new ArgumentNullException("factory");
            
            app.ValidateOptions(identityServerOptions, options);

            OptionsState.Current.RegisterConfiguration(identityServerOptions, options);

            DependenciesConfig.Configure(identityServerOptions, options);

            factory.ViewService = new Registration<IViewService>(typeof(LocaleViewServices));

            app.ConfigureIdentityServerBaseUrl(identityServerOptions.PublicOrigin);

            app.UseEmbeddedResourceFile(
                        "wwwroot/",
                        "/fonts",
                        "/content",
                        "/scripts"
                        );

            var httpConfig = WebApiConfig.Configure(identityServerOptions);
            app.UseWebApi(httpConfig);

            return app;
        }
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            app.Map("/core", coreApp =>
                {
                    // allow cross origin calls
                    coreApp.UseCors(CorsOptions.AllowAll);

                    var factory = Factory.Create(
                        issuerUri: "https://idsrv3.com",
                        siteName: "Thinktecture IdentityServer v3 - preview 1",
                        publicHostAddress: "http://localhost:3333/core");

                    //factory.UserService = Registration.RegisterFactory<IUserService>(Thinktecture.IdentityServer.MembershipReboot.UserServiceFactory.Factory);
                    //factory.UserService = Registration.RegisterFactory<IUserService>(Thinktecture.IdentityServer.AspNetIdentity.UserServiceFactory.Factory);

                    var idsrvOptions = new IdentityServerOptions
                    {
                        Factory = factory,
                        AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,
                        ConfigurePlugins = ConfigurePlugins
                    };

                    coreApp.UseIdentityServer(idsrvOptions);

                });
        }
        public static IAppBuilder ConfigureIdentityServerIssuer(this IAppBuilder app, IdentityServerOptions options)
        {
            if (app == null) throw new ArgumentNullException("app");
            if (options == null) throw new ArgumentNullException("options");

            if (String.IsNullOrWhiteSpace(options.IssuerUri))
            {
                Action<IOwinContext> op = ctx =>
                {
                    var uri = ctx.Environment.GetIdentityServerBaseUrl();
                    if (uri.EndsWith("/")) uri = uri.Substring(0, uri.Length - 1);
                    options.IssuerUri = uri;
                };

                app.Use(async (ctx, next) =>
                {
                    if (op != null)
                    {
                        var tmp = op;
                        op = null;
                        tmp(ctx);
                    }

                    await next();
                });
            }

            return app;
        }
        public void Configuration(IAppBuilder app)
        {
            // Configuring logging
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            // Configuring thinktecture identity manager
            app.Map("/admin", adminApp =>
            {
                var adminFactory = new IdentityManagerServiceFactory();
                adminFactory.ConfigureSimpleIdentityManagerService();

                adminApp.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = adminFactory
                });
            });

            // Configuring thinktecture auth server with Asp.Net identity
            var factory = Factory.Configure();
            factory.ConfigureCustomServices();
            var options = new IdentityServerOptions
            {
                SiteName = "My Auth Server",
                RequireSsl = false,
                SigningCertificate = Certificate.Load(),
                Factory = factory,
                CorsPolicy = CorsPolicy.AllowAll
            };
            app.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    users : Users.Get(),
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                factory.ViewService = Registration.RegisterType<IViewService>(typeof(CustomViewService));

                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://idsrv3.com",
                    SiteName = "Thinktecture IdentityServer v3 - CustomViewService",
                    PublicHostName = "http://localhost:3333",
                    SigningCertificate = Certificate.Get(),
                    Factory = factory,
                    AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,
                    CorsPolicy = CorsPolicy.AllowAll,
                };

                coreApp.UseIdentityServer(options);
            });
        }
        public static IAppBuilder UseIdentityServer(this IAppBuilder app, IdentityServerOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");
            
            var internalConfig = new InternalConfiguration();

            if (options.DataProtector == null)
            {
                var provider = app.GetDataProtectionProvider();
                if (provider == null)
                {
                    provider = new DpapiDataProtectionProvider("idsrv3");
                }

                internalConfig.DataProtector = new HostDataProtector(provider);
            }
            else
            {
                internalConfig.DataProtector = options.DataProtector;
            }

            // thank you Microsoft for the clean syntax
            JwtSecurityTokenHandler.InboundClaimTypeMap = ClaimMappings.None;
            JwtSecurityTokenHandler.OutboundClaimTypeMap = ClaimMappings.None;

            app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = Constants.PrimaryAuthenticationType, CookieName = Constants.PrimaryAuthenticationType });
            app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = Constants.ExternalAuthenticationType, CookieName = Constants.ExternalAuthenticationType, AuthenticationMode = AuthenticationMode.Passive });
            app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = Constants.PartialSignInAuthenticationType, CookieName = Constants.PartialSignInAuthenticationType, AuthenticationMode = AuthenticationMode.Passive });

            if (options.ConfigurePlugins != null)
            {
                options.ConfigurePlugins(app, options);
            }

            if (options.AdditionalIdentityProviderConfiguration != null)
            {
                options.AdditionalIdentityProviderConfiguration(app, Constants.ExternalAuthenticationType);
            }

            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString("/assets"),
                FileSystem = new EmbeddedResourceFileSystem(typeof(Constants).Assembly, "Thinktecture.IdentityServer.Core.Assets")
            });
            app.UseStageMarker(PipelineStage.MapHandler);

            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString("/assets/libs/fonts"),
                FileSystem = new EmbeddedResourceFileSystem(typeof(Constants).Assembly, "Thinktecture.IdentityServer.Core.Assets.libs.bootstrap.fonts")
            });
            app.UseStageMarker(PipelineStage.MapHandler);

            app.Use<AutofacContainerMiddleware>(AutofacConfig.Configure(options, internalConfig));
            Microsoft.Owin.Infrastructure.SignatureConversions.AddConversions(app);
            app.UseWebApi(WebApiConfig.Configure());

            return app;
        }
        public static TokenRequestValidator CreateTokenRequestValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IRefreshTokenStore refreshTokens = null,
            IUserService userService = null,
            ICustomGrantValidator customGrantValidator = null,
            ICustomRequestValidator customRequestValidator = null,
            ScopeValidator scopeValidator = null,
            IDictionary<string, object> environment = 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();
            }

            if (customGrantValidator == null)
            {
                customGrantValidator = new TestGrantValidator();
            }

            if (refreshTokens == null)
            {
                refreshTokens = new InMemoryRefreshTokenStore();
            }

            if (scopeValidator == null)
            {
                scopeValidator = new ScopeValidator(scopes);
            }

            IOwinContext context;
            if (environment == null)
            {
                context = new OwinContext(new Dictionary<string, object>());
            }
            else
            {
                context = new OwinContext(environment);
            }


            return new TokenRequestValidator(options, authorizationCodeStore, refreshTokens, userService, scopes, customGrantValidator, customRequestValidator, scopeValidator, context);
        }
 public AuthenticationController(IViewService viewService, IUserService userService, IExternalClaimsFilter externalClaimsFilter, AuthenticationOptions authenticationOptions, IdentityServerOptions idSvrOptions)
 {
     _viewService = viewService;
     _userService = userService;
     _externalClaimsFilter = externalClaimsFilter;
     _authenticationOptions = authenticationOptions;
     _options = idSvrOptions;
 }
 public AuthorizeInteractionResponseGenerator(IdentityServerOptions options, IConsentService consent, IUserService users, ILocalizationService localizationService)
 {
     _signIn = new SignInMessage();
     _options = options;
     _consent = consent;
     _users = users;
     _localizationService = localizationService;
 }
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
            //LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            // 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 = InMemoryFactory.Create(
                        users:   Users.Get(),
                        clients: Clients.Get(),
                        scopes:  Scopes.Get());

                    factory.CustomGrantValidator = 
                        new Registration<ICustomGrantValidator>(typeof(CustomGrantValidator));

                    factory.ConfigureClientStoreCache();
                    factory.ConfigureScopeStoreCache();
                    factory.ConfigureUserServiceCache();

                    var idsrvOptions = new IdentityServerOptions
                    {
                        SiteName = "Thinktecture IdentityServer v3",
                        Factory = factory,
                        SigningCertificate = Cert.Load(),

                        CorsPolicy = CorsPolicy.AllowAll,

                        AuthenticationOptions = new AuthenticationOptions 
                        {
                            IdentityProviders = ConfigureIdentityProviders,
                        },

                        DiagnosticsOptions = new LoggingOptions
                        {
                            EnableHttpLogging = true, 
                            EnableWebApiDiagnostics = true,
                            IncludeSensitiveDataInLogs = true
                        },

                        EventsOptions = new EventsOptions
                        {
                            RaiseFailureEvents = true,
                            RaiseInformationEvents = true,
                            RaiseSuccessEvents = true,
                            RaiseErrorEvents = true
                        }
                    };

                    coreApp.UseIdentityServer(idsrvOptions);
                });

            // only for showing the getting started index page
            app.UseStaticFiles();
        }
        public static IContainer Configure(IdentityServerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (options.Factory == null)
            {
                throw new InvalidOperationException("null factory");
            }

            IdentityServerServiceFactory fact = options.Factory;

            fact.Validate();

            var builder = new ContainerBuilder();

            builder.RegisterInstance(options).AsSelf();

            // mandatory from factory
            builder.Register(fact.UserService);
            builder.Register(fact.ScopeStore);
            builder.Register(fact.ClientStore);

            // optional from factory
            if (fact.AuthorizationCodeStore != null)
            {
                builder.Register(fact.AuthorizationCodeStore);
            }
            else
            {
                var inmemCodeStore = new InMemoryAuthorizationCodeStore();
                builder.RegisterInstance(inmemCodeStore).As <IAuthorizationCodeStore>();
            }

            if (fact.TokenHandleStore != null)
            {
                builder.Register(fact.TokenHandleStore);
            }
            else
            {
                var inmemTokenHandleStore = new InMemoryTokenHandleStore();
                builder.RegisterInstance(inmemTokenHandleStore).As <ITokenHandleStore>();
            }

            if (fact.RefreshTokenStore != null)
            {
                builder.Register(fact.RefreshTokenStore);
            }
            else
            {
                var inmemRefreshTokenStore = new InMemoryRefreshTokenStore();
                builder.RegisterInstance(inmemRefreshTokenStore).As <IRefreshTokenStore>();
            }

            if (fact.ConsentStore != null)
            {
                builder.Register(fact.ConsentStore);
            }
            else
            {
                var inmemConsentStore = new InMemoryConsentStore();
                builder.RegisterInstance(inmemConsentStore).As <IConsentStore>();
            }

            if (fact.ClaimsProvider != null)
            {
                builder.Register(fact.ClaimsProvider);
            }
            else
            {
                builder.RegisterType <DefaultClaimsProvider>().As <IClaimsProvider>();
            }

            if (fact.TokenService != null)
            {
                builder.Register(fact.TokenService);
            }
            else
            {
                builder.RegisterType <DefaultTokenService>().As <ITokenService>();
            }

            if (fact.RefreshTokenService != null)
            {
                builder.Register(fact.RefreshTokenService);
            }
            else
            {
                builder.RegisterType <DefaultRefreshTokenService>().As <IRefreshTokenService>();
            }

            if (fact.TokenSigningService != null)
            {
                builder.Register(fact.TokenSigningService);
            }
            else
            {
                builder.RegisterType <DefaultTokenSigningService>().As <ITokenSigningService>();
            }

            if (fact.CustomRequestValidator != null)
            {
                builder.Register(fact.CustomRequestValidator);
            }
            else
            {
                builder.RegisterType <DefaultCustomRequestValidator>().As <ICustomRequestValidator>();
            }

            if (fact.AssertionGrantValidator != null)
            {
                builder.Register(fact.AssertionGrantValidator);
            }
            else
            {
                builder.RegisterType <DefaultAssertionGrantValidator>().As <IAssertionGrantValidator>();
            }

            if (fact.ExternalClaimsFilter != null)
            {
                builder.Register(fact.ExternalClaimsFilter);
            }
            else
            {
                builder.RegisterType <DefaultExternalClaimsFilter>().As <IExternalClaimsFilter>();
            }

            if (fact.CustomTokenValidator != null)
            {
                builder.Register(fact.CustomTokenValidator);
            }
            else
            {
                builder.RegisterType <DefaultCustomTokenValidator>().As <ICustomTokenValidator>();
            }

            if (fact.ConsentService != null)
            {
                builder.Register(fact.ConsentService);
            }
            else
            {
                builder.RegisterType <DefaultConsentService>().As <IConsentService>();
            }

            if (fact.ViewService != null)
            {
                builder.Register(fact.ViewService);
            }
            else
            {
                builder.RegisterType <EmbeddedAssetsViewService>().As <IViewService>();
            }

            // validators
            builder.RegisterType <TokenRequestValidator>();
            builder.RegisterType <AuthorizeRequestValidator>();
            builder.RegisterType <ClientValidator>();
            builder.RegisterType <TokenValidator>();

            // processors
            builder.RegisterType <TokenResponseGenerator>();
            builder.RegisterType <AuthorizeResponseGenerator>();
            builder.RegisterType <AuthorizeInteractionResponseGenerator>();
            builder.RegisterType <UserInfoResponseGenerator>();

            // general services
            builder.RegisterType <CookieMiddlewareTrackingCookieService>().As <ITrackingCookieService>();

            // for authentication
            var authenticationOptions = options.AuthenticationOptions ?? new AuthenticationOptions();

            builder.RegisterInstance(authenticationOptions).AsSelf();

            // load core controller
            builder.RegisterApiControllers(typeof(AuthorizeEndpointController).Assembly);

            // add any additional dependencies from hosting application
            foreach (var registration in fact.Registrations)
            {
                builder.Register(registration);
            }

            return(builder.Build());
        }