当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.AddIdentityServer方法代码示例

本文整理汇总了C#中IServiceCollection.AddIdentityServer方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddIdentityServer方法的具体用法?C# IServiceCollection.AddIdentityServer怎么用?C# IServiceCollection.AddIdentityServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.AddIdentityServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            //TODO: This is the demo cert, replace with our own
            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv4test.pfx"), "idsrv3test");

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
                options.SiteName = "Punchcard Identity Server (STS)";
                //options.IssuerUri = "http://localhost:22530/identity";
                //publicOrigin? - doesn't seem to be available in v4

            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            builder.AddCustomGrantValidator<CustomGrantValidator>();


            // for the UI
            services
                .AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new IdSvrHost.UI.CustomViewLocationExpander());
                });
            services.AddTransient<IdSvrHost.UI.Login.LoginService>();
        }
开发者ID:Estyn,项目名称:ServiceStackJWT,代码行数:30,代码来源:Startup.cs

示例2: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "idsrv3test.pfx"), "idsrv3test");

            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            builder.AddCustomGrantValidator<CustomGrantValidator>();


            // for the UI
            services
                .AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new UI.CustomViewLocationExpander());
                });
            services.AddTransient<UI.Login.LoginService>();
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:26,代码来源:Startup.cs

示例3: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv4test.pfx"), "idsrv3test");
            var builder = services.AddIdentityServer(options =>
        {
                options.SigningCertificate = cert;
            });
            
            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            builder.AddCustomGrantValidator<CustomGrantValidator>();


            // for the UI
            services
                .AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
                });
            services.AddTransient<UI.Login.LoginService>();
            services.AddTransient<UI.SignUp.SignUpService>();
            services.AddTransient<ISmsSender, MessageServices>();
            services.Configure<ASPmsSercetCredentials>(Configuration);



        }
开发者ID:Charmatzis,项目名称:IT4GOV,代码行数:32,代码来源:Startup.cs

示例4: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            OnConfigureServices(services);

            services.AddDataProtection();

            services.AddIdentityServer(Options)
                .AddInMemoryClients(Clients)
                .AddInMemoryScopes(Scopes)
                .AddInMemoryUsers(Users);
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:11,代码来源:IdentityServerPipeline.cs

示例5: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            OnConfigureServices(services);

            services.AddDataProtection();

            Options.SigningCertificate = new X509Certificate2(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "idsrvtest.pfx"), "idsrv3test");

            services.AddIdentityServer(Options)
                .AddInMemoryClients(Clients)
                .AddInMemoryScopes(Scopes)
                .AddInMemoryUsers(Users);
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:15,代码来源:IdentityServerPipeline.cs

示例6: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv3test.pfx"), "idsrv3test");

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
                options.IssuerUri = "https://idsrv4";
                options.Endpoints.EnableAuthorizeEndpoint = false;
            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(new List<InMemoryUser>());
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:15,代码来源:Startup.cs

示例7: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv3test.pfx"), "idsrv3test");

            services.AddAuthentication();

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
                options.IssuerUri = "https://idsrv4";
            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            builder.AddCustomGrantValidator<CustomGrantValidator>();
            builder.AddCustomGrantValidator<CustomGrantValidator2>();
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:19,代码来源:Startup.cs

示例8: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "damienbodserver.pfx"), "");

            var builder = services.AddIdentityServer()
                .SetSigningCredential(cert)
                .AddInMemoryClients(Clients.Get())
                .AddInMemoryScopes(Scopes.Get())
                .AddInMemoryUsers(Users.Get());

            // for the UI
            services
                .AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new UI.CustomViewLocationExpander());
                });
            services.AddTransient<UI.Login.LoginService>();
        }
开发者ID:wondertrap,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:19,代码来源:Startup.cs

示例9: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var source = System.IO.File.ReadAllText("g42.cert.pfx");
            var certBytes = Convert.FromBase64String(source);
            var certificate = new X509Certificate2(certBytes, "password");

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = certificate;
                options.RequireSsl = false; // should be true
            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            services.AddCors(options =>
              options.AddPolicy("AllowAllOrigins", builder1 => builder1.AllowAnyOrigin()));
    }
开发者ID:gerry123,项目名称:g42,代码行数:19,代码来源:Startup.cs

示例10: OnConfigureServices

        public override void OnConfigureServices(IServiceCollection services)
        {
            // Can't seem to get an IOptions thing here.
            //var fc = services.GetService<IOptions<FiltersConfig>>();
            var _hostingEnvironment = services.GetService<IHostingEnvironment>();
            var _appEnvironment = services.GetService<IApplicationEnvironment>();

            var jsonFilePath = Path.Combine(_appEnvironment.ApplicationBasePath, "App_Data/IdentityServer4.Clients.json");
            var cert = new X509Certificate2(Path.Combine(_appEnvironment.ApplicationBasePath, "idsrv3test.pfx"), "idsrv3test");
            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
            });
            builder.AddJsonClients(jsonFilePath);
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            builder.AddCustomGrantValidator<CustomGrantValidator>();

        }
开发者ID:ghstahl,项目名称:vNext.Jan2016Web,代码行数:20,代码来源:AutofacModule.cs

示例11: ConfigureSecurity

        private void ConfigureSecurity(IServiceCollection services)
        {            
            var identityServer = services.AddIdentityServer(options =>
            {
                // Use ONLY for developing! Never use this in production. Never.
                options.RequireSsl = false;
                options.IssuerUri = "http://localhost:5001/";
                options.SigningCertificate = _certificate;
            });

            identityServer.AddInMemoryClients(Clients.Get());
            identityServer.AddInMemoryScopes(Scopes.Get());
            identityServer.AddInMemoryUsers(Users.Get());
            
            // Enable CORS on identity server
            identityServer.Services.AddTransient<ICorsPolicyService>(p => {
                var corsService = new DefaultCorsPolicyService(p.GetRequiredService<ILogger<DefaultCorsPolicyService>>());
                corsService.AllowAll = true;
                return corsService;
            });
        }
开发者ID:thinktecture,项目名称:nodejs-aspnetcore-webapi,代码行数:21,代码来源:Startup.cs

示例12: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration["Data:DefaultConnection:ConnectionString"];

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<IDS4Context>(o => o.UseSqlServer(connectionString));

            var cert = new X509Certificate2(Path.Combine(_appEnv.ApplicationBasePath, "idsrv4test.pfx"), "idsrv3test", X509KeyStorageFlags.UserKeySet);
            var IdentityServerBuilder = services.AddIdentityServer(options =>
                {
                    options.SigningCertificate = cert;
                })
                .AddCustomGrantValidator<CustomGrantValidator>();
            //.ConfigureEntityFramework()
            //.RegisterOperationalStores()
            //.RegisterClientStore<IDS4Context>();

            // for the UI
            services.AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new UI.CustomViewLocationExpander());
                });

            services.AddTransient<Microsoft.AspNet.Identity.IRoleStore<LuigiTrabacchin.IdentityServer4.EntityFramework.Entities.Role<Int32>>, LuigiTrabacchin.IdentityServer4.EntityFramework.Identity.RoleStore<Int32>>();
            services.AddTransient<LuigiTrabacchin.IdentityServer4.EntityFramework.Stores.ScopeStore<Int32>>();
            services.AddTransient<LuigiTrabacchin.IdentityServer4.EntityFramework.Identity.UserStore<Int32>>();
            services.AddTransient<LuigiTrabacchin.IdentityServer4.EntityFramework.DbContexts.IdentityServer4Context<Int32>, IDS4Context>();
            services.AddTransient<LuigiTrabacchin.IdentityServer4.EntityFramework.Stores.ClientStore<Int32>>();

            services.AddTransient<Microsoft.AspNet.Identity.PasswordHasher<LuigiTrabacchin.IdentityServer4.EntityFramework.Entities.User<Int32>>>();
            services.AddTransient<Microsoft.AspNet.Identity.ILookupNormalizer, LuigiTrabacchin.IdentityServer4.EntityFramework.Identity.LookupNormalizer>();

            services.AddTransient<LuigiTrabacchin.IdentityServer4.EntityFramework.Identity.UserManager<Int32>>();
            services.AddTransient<UI.Login.SignInManager>();
            services.AddIdentity<LuigiTrabacchin.IdentityServer4.EntityFramework.Entities.User<Int32>, LuigiTrabacchin.IdentityServer4.EntityFramework.Entities.Role<Int32>>();


        }
开发者ID:TrabacchinLuigi,项目名称:IdentityServer4.EntityFramework,代码行数:40,代码来源:Startup.cs

示例13: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration["Production:SqliteConnectionString"];

            services.AddEntityFramework()
                .AddSqlite()
                .AddDbContext<MyIdentityDbContext>(options => options.UseSqlite(connection));

            services.AddIdentity<MyUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit = false;
                options.Password.RequireLowercase = false;
                options.Password.RequireNonLetterOrDigit = false;
                options.Password.RequireUppercase = false;
                options.Password.RequiredLength = 6;
            })
                .AddEntityFrameworkStores<MyIdentityDbContext>()
                .AddDefaultTokenProviders();

            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "damienbodserver.pfx"), "");

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
            });

            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            // for the UI
            services
                .AddMvc()
                .AddRazorOptions(razor =>
                {
                    razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
                });
            services.AddTransient<LoginService>();
        }
开发者ID:pugillum,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:39,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddWebEncoders();
            services.AddDataProtection();

            services.AddIdentityServer(options =>
            {
                options.SigningCertificate = _environment.LoadSigningCert();
                options.AuthenticationOptions.PrimaryAuthenticationScheme = CookieAuthenticationScheme;
            })
            .AddInMemoryClients(_clients)
            .AddInMemoryScopes(_scopes)
            .AddInMemoryUsers(_users);
        }
开发者ID:haoas,项目名称:IdentityServer4,代码行数:14,代码来源:MockAuthorizationPipeline.cs

示例15: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "damienbodserver.pfx"), "");

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

            var guestPolicy = new AuthorizationPolicyBuilder()
               .RequireAuthenticatedUser()
               .RequireClaim("scope", "dataEventRecords")
               .Build();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("dataEventRecordsAdmin", policyAdmin =>
                {
                    policyAdmin.RequireClaim("role", "dataEventRecords.admin");
                });
                options.AddPolicy("admin", policyAdmin =>
                {
                    policyAdmin.RequireClaim("role", "admin");
                });
                options.AddPolicy("dataEventRecordsUser", policyUser =>
                {
                    policyUser.RequireClaim("role", "dataEventRecords.user");
                });

            });

            services.AddMvc();

            services.AddTransient<IProfileService, IdentityWithAdditionalClaimsProfileService>();

            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            services.AddIdentityServer()
                .AddSigningCredential(cert)
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients())
                .AddAspNetIdentity<ApplicationUser>()
                .AddProfileService<IdentityWithAdditionalClaimsProfileService>();
        }
开发者ID:damienbod,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:48,代码来源:Startup.cs


注:本文中的IServiceCollection.AddIdentityServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。