Beispiel #1
0
        public void Configuration(IAppBuilder app)
        {
            app.Map("/core", idsrvApp =>
            {
                var identityServerServiceFactory = new IdentityServerServiceFactory()
                                                   .UseInMemoryClients(Clients.Get())
                                                   .UseInMemoryScopes(Scopes.Get());

                var customUserService = new CustomUserService();
                identityServerServiceFactory.UserService = new Registration <IUserService>(resolver => customUserService);

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

                var identityServerOptions = new IdentityServerOptions
                {
                    SiteName           = "SecuredApi IdentityServer",
                    IssuerUri          = "https://securedapiidsrv/embedded",
                    SigningCertificate = LoadCertificate(),

                    AuthenticationOptions = new AuthenticationOptions
                    {
                        IdentityProviders             = ConfigureIdentityProviders,
                        EnablePostSignOutAutoRedirect = true,
                        PostSignOutAutoRedirectDelay  = 2,
                        LoginPageLinks = new List <LoginPageLink>()
                        {
                            new LoginPageLink()
                            {
                                Type = "createaccount",
                                Text = "Create a new account",
                                Href = "~/createuseraccount"
                            }
                        },
                    },

                    Factory = identityServerServiceFactory
                };

                idsrvApp.UseIdentityServer(identityServerOptions);
            });
        }
Beispiel #2
0
 public void Configuration(IAppBuilder app)
 {
     app.Map(
         "/core",
         coreApp => {
         coreApp.UseIdentityServer(new IdentityServerOptions
         {
             SiteName           = "Standalone Identity Server",
             SigningCertificate = Cert.Load(),
             Factory            = new IdentityServerServiceFactory()
                                  .UseInMemoryClients(Clients.Get())
                                  .UseInMemoryScopes(Scopes.Get())
                                  .UseInMemoryUsers(Users.Get()),
             RequireSsl = true
         });
     });
 }
        public void Configuration(IAppBuilder app)
        {
            IdentityServerServiceFactory factory = new IdentityServerServiceFactory()
                                                   .UseInMemoryUsers(Users.Get())
                                                   .UseInMemoryScopes(Scopes.Get())
                                                   .UseInMemoryClients(Clients.Get());

            factory.CustomGrantValidators.Add(new Registration <ICustomGrantValidator>(typeof(ActAsGrantValidator)));

            var options = new IdentityServerOptions
            {
                Factory            = factory,
                SigningCertificate = Certificate.Get(),
                RequireSsl         = false
            };

            app.UseIdentityServer(options);
        }
Beispiel #4
0
        public static void Configuration(IAppBuilder app)
        {
            var factory = new IdentityServerServiceFactory()
                          .UseInMemoryClients(Clients.Get())
                          .UseInMemoryScopes(Scopes.Get())
                          .UseInMemoryUsers(Users.Get());

            //factory.ViewService = new Registration<IViewService, NBKViewService>();

            var options = new IdentityServerOptions
            {
                SiteName           = "NBK Identity Server",
                SigningCertificate = LoadCertificate(),
                Factory            = factory,
                RequireSsl         = false //,
                                           //AuthenticationOptions = new AuthenticationOptions() { EnablePostSignOutAutoRedirect = true }  //allow auto redirect to client after sign out
            };

            app.UseIdentityServer(options);
        }
Beispiel #5
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();
            });
        }
Beispiel #6
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);
        }
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                var idServerServiceFactory = new IdentityServerServiceFactory()
                                             .UseInMemoryClients(Clients.Get())
                                             .UseInMemoryUsers(Users.Get())
                                             .UseInMemoryScopes(Scopes.Get());


                var options = new IdentityServerOptions
                {
                    Factory            = idServerServiceFactory,
                    SiteName           = "Identity Server",
                    IssuerUri          = "https://identityserversts/identity",
                    PublicOrigin       = "https://localhost:44311/",
                    SigningCertificate = LoadCertificate()
                };

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

            var factory = new IdentityServerServiceFactory()
                          .UseInMemoryUsers(Users.Get().ToList())
                          .UseInMemoryClients(Clients.Get())
                          .UseInMemoryScopes(Scopes.Get());

            var options = new IdentityServerOptions
            {
                SiteName = "IdentityServer3 - WsFed",

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

            appBuilder.UseIdentityServer(options);
        }
Beispiel #9
0
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888

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

                var options = new IdentityServerOptions
                {
                    Factory            = idServerServiceFactory,
                    SiteName           = "Standalone Identity Server",
                    IssuerUri          = Constants.IssuerUri,
                    PublicOrigin       = Constants.STSOrigin,
                    SigningCertificate = LoadCertificate()
                };

                idsrvApp.UseIdentityServer(options);
            });
        }
Beispiel #10
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();


            var certFile = env.ApplicationBasePath + $"{System.IO.Path.DirectorySeparatorChar}idsrv3test.pfx";

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

                SigningCertificate    = new X509Certificate2(certFile, "idsrv3test"),
                AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
                {
                    IdentityProviders             = UseOpenIdConnectAuthentications,
                    EnablePostSignOutAutoRedirect = true,
                    CookieOptions = new IdentityServer3.Core.Configuration.CookieOptions()
                    {
                        SlidingExpiration = true
                    }
                },
                RequireSsl = false
            };

            app.UseIdentityServer(idsrvOptions);
        }
Beispiel #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var cert    = new X509Certificate2(Path.Combine(Environment.ContentRootPath, "idsrvtest.pfx"), "idsrv3test");
            var builder = services.AddIdentityServer(options =>
            {
                options.AuthenticationOptions = new IdentityServer4.Configuration.AuthenticationOptions
                {
                    PrimaryAuthenticationScheme = "Cookies"
                };
            })
                          .AddInMemoryClients(Clients.Get())
                          .AddInMemoryScopes(Scopes.Get())
                          .SetSigningCredential(cert);

            services.AddTransient <IProfileService, AspIdProfileService>();

            // Add framework services.
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>(options =>
            {
                options.Cookies.ApplicationCookie.AuthenticationScheme = "Cookies";
                options.ClaimsIdentity.UserIdClaimType   = JwtClaimTypes.Subject;
                options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
                options.ClaimsIdentity.RoleClaimType     = JwtClaimTypes.Role;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();
            services.AddTransient <IUserClaimsPrincipalFactory <ApplicationUser>, IdentityServerUserClaimsPrincipalFactory>();

            services.AddMvc();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();
        }
Beispiel #12
0
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName = "IdentityServer",
                    //SigningCertificate = LoadCertificate(),

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

                    AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
                    {
                        IdentityProviders = ConfigureIdentityProviders
                    }
                });
            });
            app.UseResourceAuthorization(new AuthorizationManager());

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

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority    = "https://localhost:44352/identity",
                ClientId     = "mvc",
                Scope        = "openid profile roles sampleApi",
                RedirectUri  = "https://localhost:44352/",
                ResponseType = "code id_token token",

                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));
                    }
                }
            });
        }
Beispiel #13
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var l = new LoggerConfiguration()
                    .WriteTo.Trace(outputTemplate: "{Timestamp} [{Level}] ({Name}){NewLine} {Message}{NewLine}{Exception}")
                    .WriteTo.File("c:\\temp\\identityServer.log")
                    .CreateLogger();

            //appBuilder.SetLoggerFactory(new SerilogWeb.Owin.LoggerFactory(l));

            Log.Logger = l;

            /*var factory = new IdentityServerServiceFactory()
             *          .UseInMemoryScopes(Scopes.Get());
             *
             * factory.UserService = new Registration<IUserService, CustomUserService>();
             * factory.ViewService = new Registration<IViewService,CustomViewService>();
             * factory.ClientStore = new Registration<IClientStore, CustomClientStore>();
             * //factory.RefreshTokenService = new Registration<IRefreshTokenService, CustomRefreshTokenService>();
             * factory.EventService = new Registration<IEventService, CustomEventService>();*/

            // Create and modify default settings
            var settings = IdentityServer3.MongoDb.StoreSettings.DefaultSettings();

            settings.ConnectionString = "mongodb://*****:*****@localhost:27017/?connectTimeoutMS=30000&authMechanism=SCRAM-SHA-1";
            settings.Database         = "oauth2bench";

            // Create the MongoDB factory
            var factory = new IdentityServer3.MongoDb.ServiceFactory(new Registration <IUserService, CustomUserService>(), settings);

            // Overwrite services, e.g. with in memory stores
            factory.ClientStore  = new Registration <IClientStore, CustomClientStore>();
            factory.ViewService  = new Registration <IViewService, CustomViewService>();
            factory.EventService = new Registration <IEventService, CustomEventService>();
            factory.ScopeStore   = new Registration <IScopeStore>(new InMemoryScopeStore(Scopes.Get()));

            var options = new IdentityServerOptions
            {
                SigningCertificate = Certificate.Load(),
                Factory            = factory,
                EventsOptions      = new EventsOptions {
                    RaiseSuccessEvents = true, RaiseFailureEvents = true, RaiseErrorEvents = true, RaiseInformationEvents = true
                }
            };

            appBuilder.Map("/core", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(options);
            });

            appBuilder.Map("/winrthelper", app =>
            {
                app.Run(ctx =>
                {
                    ctx.Response.ContentType = "text/html";
                    return(ctx.Response.WriteAsync($@"<!DOCTYPE html>
<html>
<head><script>window.external.notify(document.location);</script></head><body>QueryString : {ctx.Request.QueryString}</body></html>"));
                });
            });
        }