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);
            });
        }
        /// <summary>
        /// Method to decide which view service to use
        /// </summary>
        private void LoadViewService(IdentityServerServiceFactory factory)
        {
            var configService = new ApplicationSettingsConfigurationService();
            var viewType      = configService.GetSetting("ViewService", "Default");

            switch (viewType)
            {
            case "CustomStyle":
                //For the default view, but with our own stylesheet
                var viewOptions = new DefaultViewServiceOptions();
                viewOptions.Stylesheets.Add("/CustomView/Styles/DefaultViewStyles.css");
                viewOptions.CacheViews = false;
                factory.ConfigureDefaultViewService(viewOptions);     //Put the options with custom stylesheet or javascript into the factory
                break;

            case "FullCustomView":
                //For a complete custom view
                factory.ViewService = new Registration <IViewService>(typeof(CustomViewService));
                break;

            default:
                //Do nothing!
                break;
            }
        }
Example #3
0
        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 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);
        }
Example #5
0
        public void Configuration(IAppBuilder app)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Trace()
                         .CreateLogger();

            app.Map("/core", coreApp =>
            {
                var factory = new IdentityServerServiceFactory()
                              .UseInMemoryUsers(Users.Get())
                              .UseInMemoryClients(Clients.Get())
                              .UseInMemoryScopes(Scopes.Get());

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

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

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

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

                coreApp.UseIdentityServer(options);
            });
        }
Example #6
0
        public static void UseIdentityServerCustomStoreSetup(this IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new SimpleDiagnosticLoggerProvider(AppDomain.CurrentDomain.SetupInformation.ApplicationBase));
            LogProvider.GetCurrentClassLogger().Log(IdentityServer3.Core.Logging.LogLevel.Info, () => { return("Starting up custom store implementation..."); });

            var requireSsl = true;

#if DEBUG
            requireSsl = false;
#endif

            app.Map("/Identity", idApp =>
            {
                var options = new IdentityServerOptions
                {
                    SiteName           = "Glavs Secret Identity Server",
                    RequireSsl         = requireSsl,
                    IssuerUri          = "http://AuthOmeSite.com",
                    SigningCertificate = CertificateLoader.LoadCertificate(),

                    LoggingOptions    = GetFullLoggingConfig(),
                    Factory           = new IdentityServerServiceFactory(),
                    EnableWelcomePage = true
                };

                // View options for things like consent form
                var viewOptions = new DefaultViewServiceOptions();
                viewOptions.Stylesheets.Add("/Content/IdentityServer/CustomIdentityServerStyles.css");
                viewOptions.CustomViewDirectory = string.Format("{0}\\Content\\IdentityServer", AppDomain.CurrentDomain.BaseDirectory);


                options.Factory.CorsPolicyService = new Registration <ICorsPolicyService>(new DefaultCorsPolicyService {
                    AllowAll = true
                });
                options.EnableWelcomePage = false;
#if DEBUG
                options.EnableWelcomePage = true;
#endif

#if DEBUG
                viewOptions.CacheViews = false;
#endif
                options.Factory.ConfigureDefaultViewService(viewOptions);

                // Entity framework data persistence
                //var efConfig = new EntityFrameworkServiceOptions
                //{
                //    ConnectionString = "IdSvr3Config",
                //    Schema = "Identity"
                //};
                //options.Factory.RegisterOperationalServices(efConfig);
                SetupCustomImplementationHooks(options);


                idApp.UseIdentityServer(options);
            });
        }
Example #7
0
        private static IdentityServerOptions ConfigureIdentityServer(string certFile)
        {
            //var certFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "idsrv3test.pfx");
            var factory =
                new IdentityServerServiceFactory().UseInMemoryUsers(Users.Get())
                .UseInMemoryClients(Clients.Get())
                .UseInMemoryScopes(Scopes.Get());

            var viewOptions = new DefaultViewServiceOptions();

            viewOptions.Stylesheets.Add("/Content/Site.css");
            viewOptions.CacheViews = false;
            factory.ConfigureDefaultViewService(viewOptions);
            factory.ViewService = new IdentityServer3.Core.Configuration.Registration <IViewService>(typeof(CustomViewService));

            //var userService = new LocalRegistrationUserService();
            //factory.UserService = new Registration<IUserService>(resolver => userService);
            //            factory.UserService = new Registration<IUserService, UserService>();

            //   factory.ClaimsProvider = new IdentityServer3.Core.Configuration.Registration<IClaimsProvider>(typeof(CustomClaimsProvider));
            //   factory.UserService = new IdentityServer3.Core.Configuration.Registration<IUserService>(typeof(CustomUserService));
            //    factory.CustomGrantValidators.Add(new IdentityServer3.Core.Configuration.Registration<ICustomGrantValidator>(typeof(CustomGrantValidator)));
            factory.CorsPolicyService = new IdentityServer3.Core.Configuration.Registration <ICorsPolicyService>(new DefaultCorsPolicyService()
            {
                AllowAll = true
            });
            var options = new IdentityServerOptions
            {
                RequireSsl            = false,
                SiteName              = "Janitor - Mequanta Identity Service",
                Factory               = factory,
                SigningCertificate    = new X509Certificate2(certFile, "idsrv3test"),
                AuthenticationOptions = new AuthenticationOptions
                {
                    IdentityProviders = ConfigureIdentityProviders,
                    LoginPageLinks    = new LoginPageLink[]
                    {
                        new LoginPageLink()
                        {
                            Text = "Register",
                            Href = "localregistration"
                        }
                    }
                },
                PluginConfiguration = ConfigurePlugins,
                EventsOptions       = new EventsOptions()
                {
                    RaiseSuccessEvents     = true,
                    RaiseErrorEvents       = true,
                    RaiseFailureEvents     = true,
                    RaiseInformationEvents = true
                }
            };

            return(options);
        }
Example #8
0
        public IdentityServerServiceFactory Initialize(string connectionStringName)
        {
            var defaultViewServiceOptions = new DefaultViewServiceOptions();

            defaultViewServiceOptions.Stylesheets.Add(_configurationManager.GetByKey("Assets.bulma.css"));
            defaultViewServiceOptions.Stylesheets.Add(_configurationManager.GetByKey("Assets.error.css"));
            defaultViewServiceOptions.Stylesheets.Add(_configurationManager.GetByKey("Assets.forgotPassword.css"));
            defaultViewServiceOptions.Stylesheets.Add(_configurationManager.GetByKey("Assets.login.css"));
            defaultViewServiceOptions.CacheViews = false;

            var factory = new IdentityServerServiceFactory();

            factory.ConfigureDefaultViewService(defaultViewServiceOptions);

            var entityFrameworkOptions = new EntityFrameworkServiceOptions
            {
                ConnectionString = connectionStringName
            };

            factory.RegisterConfigurationServices(entityFrameworkOptions);
            factory.RegisterOperationalServices(entityFrameworkOptions);

            factory.Register(new Registration <CloudPlusAuthDbContext>());
            factory.Register(new Registration <UserStore>());
            factory.Register(new Registration <RoleStore>());
            factory.Register(new Registration <IdentityUserManager>());
            factory.Register(new Registration <IdentityRoleManager>());
            factory.Register(new Registration <IConfigurationManager, ConfigurationManager>());
            factory.Register(new Registration <IImpersonateUserService, ImpersonateUserService>());
            factory.Register(new Registration <IHttpClientResolver, HttpClientResolver>());
            factory.Register(new Registration <IPermissionService, PermissionService>());
            factory.Register(new Registration <CloudPlus.Services.Identity.User.IUserService, UserService>());

            factory.Register(new Registration <ITokenProviderService>(x =>
                                                                      new TokenProviderService(x.Resolve <IdentityUserManager>(),
                                                                                               x.Resolve <CloudPlusAuthDbContext>())));

            factory.UserService = new Registration <IUserService>(resolver =>
                                                                  new IdentityUserService(
                                                                      resolver.Resolve <IdentityUserManager>(),
                                                                      resolver.Resolve <IImpersonateUserService>(),
                                                                      resolver.Resolve <IConfigurationManager>()));

            factory.ClaimsProvider = new Registration <IClaimsProvider>(typeof(IdentityClaimsProvider));

            factory.CorsPolicyService =
                new Registration <ICorsPolicyService>(new DefaultCorsPolicyService
            {
                AllowAll = true
            });

            return(factory);
        }
Example #9
0
 public MvcViewService(
     HttpContextBase httpContext,
     DefaultViewServiceOptions config,
     IViewLoader viewLoader,
     IControllerFactory controllerFactory,
     ViewEngineCollection viewEngineCollection)
 {
     this.httpContext          = httpContext;
     this.config               = config;
     this.defaultViewService   = new DefaultViewService(this.config, viewLoader);
     this.controllerFactory    = controllerFactory;
     this.viewEngineCollection = viewEngineCollection;
 }
        public void Configuration(IAppBuilder appBuilder)
        {
            appBuilder.Map("/identity", identityServerAppBuilder =>
            {
                var identityServerServiceFactory = new IdentityServerServiceFactory();

                var entityFrameworkServiceOptions = new EntityFrameworkServiceOptions
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["CpimIdentityServerDbConnectionString"].ConnectionString
                };

                identityServerServiceFactory.RegisterClientStore(entityFrameworkServiceOptions);
                identityServerServiceFactory.UseInMemoryScopes(Scopes.Get());
                identityServerServiceFactory.UseInMemoryUsers(Users.Get());

                // Add custom user service
                var userService = new UserService();
                identityServerServiceFactory.UserService = new Registration <IUserService>(resolver => userService);

                var defaultViewServiceOptions = new DefaultViewServiceOptions
                {
                    CacheViews = false
                };

                defaultViewServiceOptions.Stylesheets.Add("/Styles/site.css");
                identityServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions);

                var options = new IdentityServerOptions
                {
                    LoggingOptions = new LoggingOptions()
                    {
                        WebApiDiagnosticsIsVerbose = true
                    },
                    AuthenticationOptions = new AuthenticationOptions
                    {
                        IdentityProviders = ConfigureIdentityProviders
                    },
                    Factory            = identityServerServiceFactory,
                    IssuerUri          = Settings.Default.IdentityServerRedirectUri,
                    PublicOrigin       = Settings.Default.Origin,
                    RequireSsl         = false,
                    SigningCertificate = LoadCertificate(),
                    SiteName           = Settings.Default.SiteName
                };

                identityServerAppBuilder.UseIdentityServer(options);
                ConfigureMvc();
            });
        }
Example #11
0
        public void Configuration(IAppBuilder app)
        {
            var entityFrameworkOptions = new EntityFrameworkServiceOptions
            {
                ConnectionString =
                    ConfigurationManager.ConnectionStrings["SocialNetwork.Idsvr"].ConnectionString
            };

            var inMemoryManager = new InMemoryManager();

            SetupClients(inMemoryManager.GetClients(), entityFrameworkOptions);
            SetupScopes(inMemoryManager.GetScopes(), entityFrameworkOptions);

            var userRepository = new UserRepository(
                () => new SqlConnection(ConfigurationManager.ConnectionStrings["SocialNetwork"].ConnectionString)
                );

            var viewServiceOptions = new DefaultViewServiceOptions();

            viewServiceOptions.Stylesheets.Add("/css/site.css");

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(entityFrameworkOptions);
            factory.RegisterOperationalServices(entityFrameworkOptions);
            factory.UserService = new Registration <IUserService>(
                typeof(SocialNetworkUserService));
            factory.Register(new Registration <IUserRepository>(userRepository));
            factory.ConfigureDefaultViewService(viewServiceOptions);

            new TokenCleanup(entityFrameworkOptions, 1).Start();

            var certificate = Convert.FromBase64String(ConfigurationManager.AppSettings["SigningCertificate"]);

            var options = new IdentityServerOptions
            {
                SiteName           = "OAuth is fun!",
                SigningCertificate = new X509Certificate2(certificate, ConfigurationManager.AppSettings["SigningCertificatePassword"]),
                RequireSsl         = false, // DO NOT DO THIS IN
                Factory            = factory,
            };

            app.UseIdentityServer(options);
        }
Example #12
0
        /// <summary>
        /// Configures the default view service.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="options">The default view service options.</param>
        /// <exception cref="System.ArgumentNullException">
        /// factory
        /// or
        /// options
        /// </exception>
        /// <exception cref="System.InvalidOperationException">ViewService is already configured</exception>
        public static void ConfigureDefaultViewService(this IdentityServerServiceFactory factory,
                                                       DefaultViewServiceOptions options)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (factory.ViewService != null)
            {
                throw new InvalidOperationException("A ViewService is already configured");
            }

            factory.ViewService = new DefaultViewServiceRegistration(options);
        }
Example #13
0
        public void Configuration(IAppBuilder appBuilder)
        {
            appBuilder.Map("/identity", identityServerAppBuilder =>
            {
                var identityServerServiceFactory = new IdentityServerServiceFactory();

                var entityFrameworkServiceOptions = new EntityFrameworkServiceOptions
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["CpimIdentityServerDbConnectionString"].ConnectionString
                };

                identityServerServiceFactory.RegisterClientStore(entityFrameworkServiceOptions);
                identityServerServiceFactory.UseInMemoryScopes(Scopes.Get());
                identityServerServiceFactory.UseInMemoryUsers(Users.Get());

                var defaultViewServiceOptions = new DefaultViewServiceOptions
                {
                    CacheViews = false
                };

                defaultViewServiceOptions.Stylesheets.Add("/Styles/site.css");
                identityServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions);

                var options = new IdentityServerOptions
                {
                    AuthenticationOptions = new AuthenticationOptions
                    {
                        IdentityProviders = ConfigureIdentityProviders
                    },
                    Factory            = identityServerServiceFactory,
                    IssuerUri          = "https://b2cauth.azurewebsites.net/identity",
                    PublicOrigin       = "https://b2cauth.azurewebsites.net",
                    RequireSsl         = false,
                    SigningCertificate = LoadCertificate(),
                    SiteName           = Settings.Default.SiteName
                };

                identityServerAppBuilder.UseIdentityServer(options);
                ConfigureMvc();
            });
        }
Example #14
0
        private static void SetFactoryAndViewOpptions(IdentityServerOptions options)
        {
            var viewOptions = new DefaultViewServiceOptions();

            viewOptions.Stylesheets.Add("/Content/IdentityServer/CustomIdentityServerStyles.css");
            viewOptions.CustomViewDirectory = string.Format("{0}\\Content\\IdentityServer", AppDomain.CurrentDomain.BaseDirectory);


            options.Factory.CorsPolicyService = new Registration <ICorsPolicyService>(new DefaultCorsPolicyService {
                AllowAll = true
            });
            options.EnableWelcomePage = false;
#if DEBUG
            options.EnableWelcomePage = true;
#endif

#if DEBUG
            viewOptions.CacheViews = false;
#endif
            options.Factory.ConfigureDefaultViewService(viewOptions);
        }
Example #15
0
        private void configureIdentityServerFromDatabase(IAppBuilder app)
        {
            var entityFrameworkOptions = new EntityFrameworkServiceOptions
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["SocialNetwork.IdSvr"].ConnectionString
            };
            var inmemoryManager = new InMemoryManager();

            var userRepository = new UserRepository(
                () => new SqlConnection(ConfigurationManager.ConnectionStrings["SocialNetwork"].ConnectionString)
                );

            var viewServiceOptions = new DefaultViewServiceOptions();
            //viewServiceOptions.Stylesheets.Add("/css/bootstrap.min.css");

            var factory = new IdentityServerServiceFactory();

            SetupClients(inmemoryManager.GetClients(), entityFrameworkOptions);
            SetupScopes(inmemoryManager.GetScopes(), entityFrameworkOptions);

            factory.RegisterConfigurationServices(entityFrameworkOptions);
            factory.RegisterOperationalServices(entityFrameworkOptions);
            factory.UserService = new Registration <IdentityServer3.Core.Services.IUserService>(typeof(SocialNetworkUserService));
            factory.Register(new Registration <IUserRepository>(userRepository));
            factory.ConfigureDefaultViewService <CustomViewService>(viewServiceOptions);

            new TokenCleanup(entityFrameworkOptions, 1).Start();

            var certificate = Convert.FromBase64String(ConfigurationManager.AppSettings["SigningCertificate"]);

            var options = new IdentityServerOptions()
            {
                SiteName           = "Facenotebook!!!",
                SigningCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certificate, "password"),
                RequireSsl         = false,
                Factory            = factory
            };

            app.UseIdentityServer(options);
        }
Example #16
0
        public void Configure(IApplicationBuilder app, IApplicationEnvironment env, ILoggerFactory loggerFactory)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.LiterateConsole()
                         .CreateLogger();

            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            app.UseIISPlatformHandler();
            app.UseStaticFiles();


            var certFile = env.ApplicationBasePath + "\\idsrv3test.pfx";

            var idsrvOptions = new IdentityServerOptions
            {
                Factory = new IdentityServerServiceFactory()
                          .UseInMemoryUsers(Users.Get())
                          .UseInMemoryClients(Clients.Get())
                          .UseInMemoryScopes(Scopes.Get()),

                SigningCertificate = new X509Certificate2(certFile, "idsrv3test"),
                RequireSsl         = false
            };

            var viewOptions = new DefaultViewServiceOptions();

            viewOptions.Stylesheets.Add("/css/Site.css");
            viewOptions.CacheViews = false;

            var templatePath = System.IO.Path.Combine(env.ApplicationBasePath, "templates");

            viewOptions.ViewLoader = new Registration <IViewLoader>(new FileSystemWithEmbeddedFallbackViewLoader(templatePath));
            idsrvOptions.Factory.ConfigureDefaultViewService(viewOptions);


            app.UseIdentityServer(idsrvOptions);
        }
Example #17
0
        private static IdentityServerServiceFactory ConfigureFactory(SsoServiceEnvironmentConfiguration environment)
        {
            var connectionString = environment.TableStorageConnectionString;

            var factory = new IdentityServerServiceFactory();

            var viewOptions = new DefaultViewServiceOptions();

#if DEBUG
            viewOptions.CacheViews = false;
#endif
            viewOptions.Stylesheets.Add("https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/united/bootstrap.min.css");
            viewOptions.Stylesheets.Add("https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css");
            viewOptions.Stylesheets.Add("https://appsyndication.azureedge.net/css/site.css");
#if DEBUG
            viewOptions.Stylesheets.Add("/sso/css/site.css");
#endif
            viewOptions.Scripts.Add("https://code.jquery.com/jquery-1.12.3.min.js");
            viewOptions.Scripts.Add("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js");
            viewOptions.Scripts.Add("https://appsyndication.azureedge.net/js/site.js");

            factory.ConfigureDefaultViewService(viewOptions);

            var scopes = Scopes.Get();

            var scopeStore = new InMemoryScopeStore(scopes);
            factory.ScopeStore = new Registration <IScopeStore>(scopeStore);

            var clients = Clients.Get(environment);

            var clientStore = new InMemoryClientStore(clients);
            factory.ClientStore = new Registration <IClientStore>(clientStore);

            factory.UserService = new Registration <IUserService, UserService>();
            factory.Register(new Registration <AtsUserService>());
            factory.Register(new Registration <AtsUserRepository>());
            factory.Register(new Registration <AtsUserServiceConfig>(r => new AtsUserServiceConfig(connectionString, "appsyndication")));

            return(factory);
        }
        public static void UseIdentityServerCustomViewSetup(this IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new SimpleDiagnosticLoggerProvider(AppDomain.CurrentDomain.SetupInformation.ApplicationBase));
            LogProvider.GetCurrentClassLogger().Log(IdentityServer3.Core.Logging.LogLevel.Info, () => { return("Starting up custom view implementation..."); });

            var requireSsl = true;

#if DEBUG
            requireSsl = false;
#endif

            app.Map("/Identity", idApp =>
            {
                var options = new IdentityServerOptions
                {
                    SiteName           = "Glavs Secret Identity Server",
                    RequireSsl         = requireSsl,
                    IssuerUri          = "http://AuthOmeSite.com",
                    SigningCertificate = CertificateLoader.LoadCertificate(),

                    LoggingOptions    = GetFullLoggingConfig(),
                    Factory           = GetInMemoryFactoryOptions(),
                    EnableWelcomePage = true
                };

                // View options for things like consent form
                var viewOptions = new DefaultViewServiceOptions();
                viewOptions.Stylesheets.Add("/Content/IdentityServer/CustomIdentityServerStyles.css");
                viewOptions.CustomViewDirectory = string.Format("{0}\\Content\\IdentityServer", AppDomain.CurrentDomain.BaseDirectory);

#if DEBUG
                viewOptions.CacheViews = false;
#endif
                options.Factory.ConfigureDefaultViewService(viewOptions);



                idApp.UseIdentityServer(options);
            });
        }
Example #19
0
        /// <summary>
        /// Configures the default view service.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="options">The default view service options.</param>
        /// <exception cref="System.ArgumentNullException">
        /// factory
        /// or
        /// options
        /// </exception>
        /// <exception cref="System.InvalidOperationException">ViewService is already configured</exception>
        public static void ConfigureDefaultViewService(this IdentityServerServiceFactory factory,
                                                       DefaultViewServiceOptions options)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (factory.ViewService != null)
            {
                throw new InvalidOperationException("A ViewService is already configured");
            }

            factory.ViewService = new Registration <IViewService, DefaultViewService>();
            factory.Register(new Registration <DefaultViewServiceOptions>(options));

            if (options.ViewLoader == null)
            {
                options.ViewLoader = new Registration <IViewLoader, FileSystemWithEmbeddedFallbackViewLoader>();
            }

            if (options.CacheViews)
            {
                factory.Register(new Registration <IViewLoader>(options.ViewLoader, InnerRegistrationName));
                var cache = new ResourceCache();
                factory.Register(new Registration <IViewLoader>(
                                     resolver => new CachingLoader(cache, resolver.Resolve <IViewLoader>(InnerRegistrationName))));
            }
            else
            {
                factory.Register(options.ViewLoader);
            }
        }
Example #20
0
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                var factory = new IdentityServerServiceFactory()
                              //.UseInMemoryUsers(Users.Get())
                              .UseInMemoryClients(Clients.Get())
                              .UseInMemoryScopes(Scopes.Get());

                var userService           = new LocalUserService();
                factory.UserService       = new Registration <IUserService>(resolver => userService);
                factory.CorsPolicyService = new Registration <ICorsPolicyService>(new DefaultCorsPolicyService {
                    AllowAll = true
                });

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

                var options = new IdentityServerOptions
                {
                    SiteName = "Goloc",

                    AuthenticationOptions = new AuthenticationOptions
                    {
                        EnablePostSignOutAutoRedirect = true
                    },

                    SigningCertificate = LoadCertificate(),
                    Factory            = factory,
                };

                idsrvApp.UseIdentityServer(options);
            });
        }
        public void Configuration(IAppBuilder app)
        {
            var clients = new List <Client>();

            clients.Add(new Client
            {
                Enabled    = true,
                ClientName = "DemoClient",
                ClientId   = "demo",
                Flow       = Flows.Implicit,

                /*
                 * Claims = new List<Claim> {
                 *  new Claim("aud", "test2")
                 * },
                 */
                RedirectUris = new List <string>
                {
                    "https://*****:*****@acme.com"),
                    new Claim(Constants.ClaimTypes.EmailVerified, "true"),
                    new Claim("projects", "A,B,C"),
                    new Claim("role", "Manager")
                }
            });

            var scopes = new List <Scope>();

            scopes.Add(new Scope
            {
                Enabled = true,
                Name    = "roles",
                Type    = ScopeType.Identity,
                Claims  = new List <ScopeClaim>
                {
                    new ScopeClaim("role")
                }
            });

            scopes.Add(new Scope
            {
                Enabled                 = true,
                Name                    = "company",
                DisplayName             = "Company-specific details",
                Description             = "Projects, Departments etc.",
                Type                    = ScopeType.Resource,
                IncludeAllClaimsForUser = true,
                Claims                  = new List <ScopeClaim>
                {
                    new ScopeClaim("projects")
                }
            });


            scopes.AddRange(StandardScopes.All);


            foreach (var scope in scopes)
            {
                foreach (var scopeClaim in scope.Claims)
                {
                    scopeClaim.AlwaysIncludeInIdToken = true;
                }
            }


            var factory = InMemoryFactory.Create(
                clients: clients,
                users: users,
                scopes: scopes);

            var viewOptions = new DefaultViewServiceOptions();

            viewOptions.Stylesheets.Add("/Content/bootstrap.min.css");
            factory.ConfigureDefaultViewService(viewOptions);

            app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName           = "IdentityServer",
                    SigningCertificate = LoadCertificate(),
                    Factory            = factory
                });
            });
        }
 public IdentityViewService(DefaultViewServiceOptions config, IViewLoader viewLoader)
     : base(config, viewLoader)
 {
 }
Example #23
0
        public void Configuration(IAppBuilder app)
        {
            // todo: replace with serilog
            //LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary <string, string>();

            app.Map("/identity", idsrvApp =>
            {
                var factory = new IdentityServerServiceFactory()
                              .UseInMemoryUsers(Users.Get())
                              .UseInMemoryClients(Clients.Get())
                              .UseInMemoryScopes(Scopes.Get());

                var viewOptions = new DefaultViewServiceOptions();
                viewOptions.Stylesheets.Add("~/Content/Site.css");
                viewOptions.Stylesheets.Add("~/Content/animation-style_css");

                viewOptions.CacheViews = false;
                factory.ConfigureDefaultViewService(viewOptions);

                var options = new IdentityServerOptions
                {
                    SiteName = "PRIS",

                    SigningCertificate = LoadCertificate(),
                    Factory            = factory,
                    RequireSsl         = false,

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

                idsrvApp.UseIdentityServer(options);
            });

            app.UseResourceAuthorization(new AuthorizationManager());

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            #region openIdConnect
            //app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            //{
            //    Authority = "https://localhost:44319/identity",

            //    ClientId = "mvc",
            //    Scope = "openid profile roles sampleApi",
            //    ResponseType = "id_token token",
            //    RedirectUri = "https://localhost:44319/",

            //    SignInAsAuthenticationType = "Cookies",
            //    UseTokenLifetime = false,

            //    Notifications = new OpenIdConnectAuthenticationNotifications
            //    {
            //        SecurityTokenValidated = async n =>
            //            {
            //                var nid = new ClaimsIdentity(
            //                    n.AuthenticationTicket.Identity.AuthenticationType,
            //                    Constants.ClaimTypes.GivenName,
            //                    Constants.ClaimTypes.Role);

            //                    // get userinfo data
            //                    var userInfoClient = new UserInfoClient(
            //                    new Uri(n.Options.Authority + "/connect/userinfo"),
            //                    n.ProtocolMessage.AccessToken);

            //                var userInfo = await userInfoClient.GetAsync();
            //                userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2)));

            //                    // keep the id_token for logout
            //                    nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));

            //                    // add access token for sample API
            //                    nid.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken));

            //                    // keep track of access token expiration
            //                    nid.AddClaim(new Claim("expires_at", DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString()));

            //                    // add some other app specific claim
            //                    nid.AddClaim(new Claim("app_specific", "some data"));

            //                n.AuthenticationTicket = new AuthenticationTicket(
            //                    nid,
            //                    n.AuthenticationTicket.Properties);
            //            },

            //        RedirectToIdentityProvider = n =>
            //            {
            //                if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
            //                {
            //                    var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

            //                    if (idTokenHint != null)
            //                    {
            //                        n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
            //                    }
            //                }

            //                return Task.FromResult(0);
            //            }
            //    }
            //});
            #endregion
        }
Example #24
0
 public CustomIdsViewService(DefaultViewServiceOptions config, IViewLoader viewLoader, ILogger logger, IControllerFactory controllerFactory)
     : base(config, viewLoader)
 {
     _logger            = logger;
     _controllerFactory = controllerFactory;
 }
Example #25
0
 public CustomIdsViewService(DefaultViewServiceOptions config, IViewLoader viewLoader)
     : this(config, viewLoader, LogManager.GetCurrentClassLogger(), ControllerBuilder.Current.GetControllerFactory())
 {
 }
Example #26
0
        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);
            });
        }
Example #27
0
        public void Configuration(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);

            app.Map("/identity", idsrvApp =>
            {
                var corsPolicyService = new DefaultCorsPolicyService()
                {
                    AllowAll = true
                };

                var defaultViewServiceOptions        = new DefaultViewServiceOptions();
                defaultViewServiceOptions.CacheViews = false;

                var idServerServiceFactory = new IdentityServerServiceFactory()
                                             .UseInMemoryClients(CustomClients.Get())
                                             .UseInMemoryScopes(CustomScopes.Get());
                //.UseInMemoryUsers(CustomUsers.Get());

                idServerServiceFactory.CorsPolicyService = new
                                                           Registration <IdentityServer3.Core.Services.ICorsPolicyService>(corsPolicyService);

                idServerServiceFactory.ConfigureDefaultViewService(defaultViewServiceOptions);

                idServerServiceFactory.Register(new Registration <ApplicationDbContext>());
                idServerServiceFactory.Register(new Registration <UserStore <ApplicationUser> >(resolver =>
                {
                    return(new UserStore <ApplicationUser>(resolver.Resolve <ApplicationDbContext>()));
                }));
                idServerServiceFactory.Register(new Registration <UserManager <ApplicationUser> >(resolver =>
                {
                    return(new ApplicationUserManager(resolver.Resolve <UserStore <ApplicationUser> >()));
                }));

                idServerServiceFactory.UserService = new Registration <IUserService, CustomUserService>();

                var options = new IdentityServerOptions
                {
                    Factory = idServerServiceFactory,

                    // Just for Angular 2 App testing.
                    RequireSsl = false,

                    SiteName              = "TripCompany Security Token Service",
                    SigningCertificate    = LoadCertificate(),
                    IssuerUri             = DBSP.RememberMe.Identity.Constants.TripGalleryIssuerUri,
                    PublicOrigin          = DBSP.RememberMe.Identity.Constants.TripGallerySTSOrigin,
                    AuthenticationOptions = new AuthenticationOptions()
                    {
                        EnablePostSignOutAutoRedirect = true,
                        LoginPageLinks = new List <LoginPageLink>()
                        {
                            new LoginPageLink()
                            {
                                Type = "createaccount",
                                Text = "Create a new account",
                                Href = "~/createuseraccount"
                            }
                        }
                    },
                    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);
            });
        }
Example #28
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new CustomLogProvider());

            app.Map("/login", coreApp =>
            {
                var factory = new IdentityServerServiceFactory()
                              .UseInMemoryClients(Clients.Get())
                              //.UseInMemoryUsers(Users.Get())
                              .UseInMemoryScopes(Scopes.Get());

                //Set the options for the default view service
                var viewOptions = new DefaultViewServiceOptions();
#if DEBUG
                //Dont cache the views when we are testing
                viewOptions.CacheViews = false;
#endif
                factory.ConfigureDefaultViewService(viewOptions);

                // different examples of custom user services
                //var userService = new RegisterFirstExternalRegistrationUserService();
                //var userService = new ExternalRegistrationUserService();
                //var userService = new EulaAtLoginUserService();
                var userService = new LocalRegistrationUserService();

                // note: for the sample this registration is a singletone (not what you want in production probably)
                factory.UserService = new Registration <IUserService>(resolver => userService);

                //Required for GPG custom interface
                //factory.ViewService = new Registration<IViewService, CustomViewService>();

                factory.EventService = new Registration <IEventService, AuditEventService>();

                var options = new IdentityServerOptions
                {
                    SiteName           = "GPG IdentityServer",
                    SigningCertificate = LoadCertificate(),
                    Factory            = factory,

                    AuthenticationOptions = new AuthenticationOptions
                    {
                        EnablePostSignOutAutoRedirect = true,
                        IdentityProviders             = ConfigureIdentityProviders,

                        EnableSignOutPrompt      = false,
                        InvalidSignInRedirectUrl = ConfigurationManager.AppSettings["GpgWebServer"],

                        LoginPageLinks = new List <LoginPageLink>()
                        {
                            new LoginPageLink()
                            {
                                Href = ConfigurationManager.AppSettings["GpgWebServerPasswordLink"],
                                Text = "Reset your password",
                                Type = "resetPassword"
                            },
                            new LoginPageLink()
                            {
                                Href = ConfigurationManager.AppSettings["GpgWebServerRegisterLink"],
                                Text = "Register",
                                Type = "localRegistration"
                            }
                        }
                    },

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

                coreApp.UseIdentityServer(options);
            });

            //app.Map("/login", idsrvApp =>
            //{
            //    idsrvApp.UseIdentityServer(new IdentityServerOptions
            //    {
            //        SiteName = "GPG IdentityServer",
            //        SigningCertificate = LoadCertificate(),

            //        Factory = new IdentityServerServiceFactory()
            //                    .UseInMemoryUsers(Users.Get())
            //                    .UseInMemoryClients(Clients.Get())
            //                    .UseInMemoryScopes(Scopes.Get()),

            //        AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
            //        {
            //            EnablePostSignOutAutoRedirect = true,
            //            IdentityProviders = ConfigureIdentityProviders,
            //            LoginPageLinks = new List<LoginPageLink>()
            //            {
            //               new LoginPageLink()
            //               {
            //                   Href = ConfigurationManager.AppSettings["GpgWebServerReminder"],
            //                   Text = "Forgotten Password?",
            //                   Type = "resetPassword"
            //               },
            //               new LoginPageLink()
            //               {
            //                   Href = ConfigurationManager.AppSettings["GpgWebServerRegister"],
            //                   Text = "Create New Account",
            //                   Type = "localRegistration"
            //               }
            //            }

            //        }
            //    });


            //});
        }
Example #29
0
 /// <summary>
 /// Конструктор просто инициализирует базовый класс.
 /// </summary>
 /// <param name="config">Объект <see cref="DefaultViewServiceOptions"/>.</param>
 /// <param name="viewLoader">Реализация <see cref="IViewLoader"/>.</param>
 public CustomViewService(DefaultViewServiceOptions config, IViewLoader viewLoader)
     : base(config, viewLoader)
 {
 }