GetIdentityResources() публичный статический Метод

public static GetIdentityResources ( ) : IEnumerable
Результат IEnumerable
Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());



            services.AddAuthentication()
            .AddGoogle("Google", options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

                options.ClientId     = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            })
            .AddOpenIdConnect("oidc", "OpenID Connect", options =>
            {
                options.SignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                options.Authority = "https://demo.identityserver.io/";
                options.ClientId  = "implicit";

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    RoleClaimType = "role"
                };
            });
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddTestUsers(Config.GetUsers());

            //services.AddAuthentication()
            //    .AddQQ(a =>
            //    {
            //        a.AppId = "";
            //        a.AppKey = "";
            //    });

            //使用OpenID Connect进行外部登录集成
            //services.AddAuthentication()
            //    .AddOpenIdConnect("oidc", "OpenID Connect", a =>
            //      {
            //          a.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //          a.SignOutScheme = IdentityServerConstants.SignoutScheme;

            //          a.Authority = "https://demo.identityserver.io/";
            //          a.ClientId = "implicit";

            //          a.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            //          {
            //              NameClaimType = "name",
            //              RoleClaimType = "role"
            //          };

            //      });


            services.AddMvc();
        }
        private void InitializeDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate();

                var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();
                context.Database.Migrate();
                if (!context.Clients.Any())
                {
                    foreach (var client in Config.GetClients())
                    {
                        context.Clients.Add(client.ToEntity());
                    }
                    context.SaveChanges();
                }

                if (!context.IdentityResources.Any())
                {
                    foreach (var resource in Config.GetIdentityResources())
                    {
                        context.IdentityResources.Add(resource.ToEntity());
                    }
                    context.SaveChanges();
                }

                if (!context.ApiResources.Any())
                {
                    foreach (var resource in Config.GetApiResources())
                    {
                        context.ApiResources.Add(resource.ToEntity());
                    }
                    context.SaveChanges();
                }
            }
        }
Пример #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            var database = services.AddMongoDatabase(Configuration);

            services.AddDataProtection()
            .SetApplicationName("identityserver")
            .PersistKeysToFileSystem(new System.IO.DirectoryInfo(@"/var/dpkeys/"));
            var mongoUserStore = new MongoUserStore(database);
            var hasher         = new PasswordHasher <MongoExternalUser>();

//            var mongoExternalUser = mongoUserStore.AutoProvisionUser("IdSrv", "alex", new List<Claim>()
//            {
//                new Claim(JwtClaimTypes.Name,"alex"),
//                new Claim(JwtClaimTypes.Email, "*****@*****.**")
//            }).Result;
//            var hash = hasher.HashPassword(mongoExternalUser as MongoExternalUser, "test");
//            var updateResult = mongoUserStore.SetPasswordHashForUser(mongoExternalUser, hash).Result;
            services.AddSingleton <MongoUserStore>(mongoUserStore);
            services.AddRepositories(database);
            services.AddMvc();



            services.AddIdentityServer()
            .AddSigningCredential(SigningCertificate.GetSigningCertificate())
            .AddMongoRepository()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddIdentityApiResources()
            .AddPersistedGrants()
            .AddInMemoryClients(Config.GetClients(Configuration))
            .AddProfileService <ProfileService>();

            services
            .AddAuthentication()
            .AddExternalAuth(Configuration);
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            _clientId     = Configuration["MicrosoftClientId"];
            _clientSecret = Configuration["MircosoftClientSecret"];

            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();

            services.AddAuthentication()
            .AddMicrosoftAccount(options =>
            {
                options.ClientId     = _clientId;
                options.SignInScheme = "Identity.External";
                options.ClientSecret = _clientSecret;
            });

            services.AddMvc();

            services.AddTransient <IProfileService, IdentityWithAdditionalClaimsProfileService>();

            services.AddTransient <IEmailSender, AuthMessageSender>();

            services.AddIdentityServer()
            .AddSigningCredential(cert)
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddAspNetIdentity <ApplicationUser>()
            .AddProfileService <IdentityWithAdditionalClaimsProfileService>();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection(options => options.ApplicationDiscriminator = "00000").SetApplicationName("00000");

            services.AddMvc();

            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer(Option =>
            {
                Option.PublicOrigin = "http://localhost:54660/IdentityServer/";
                Option.IssuerUri    = "http://localhost:54660/IdentityServer/";
            })
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());

            //CspOptions = new CspOptions
            //{
            //    Enabled = false,
            //}
            //JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            //services.AddAuthentication(options =>
            //{
            //    options.DefaultScheme = "Cookies";
            //    options.DefaultChallengeScheme = "oidc";
            //}).AddCookie("Cookies")
            //.AddOpenIdConnect("oidc", options =>
            //{
            //    options.SignInScheme = "Cookies";

            //    options.Authority = "http://localhost:54660/IdentityServer";
            //    options.RequireHttpsMetadata = false;

            //    options.ClientId = "mvc";
            //    options.ClientSecret = "secret";
            //    options.ResponseType = "code id_token";

            //    options.SaveTokens = true;
            //    options.GetClaimsFromUserInfoEndpoint = true;

            //    options.Scope.Add("api1");
            //    options.Scope.Add("offline_access");
            //});
            //services.AddAuthentication(options =>
            //{
            //    options.DefaultScheme = "ZfsoftCookies";
            //    options.DefaultChallengeScheme = "oidc";
            //    //options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            //})
            //    .AddCookie("ZfsoftCookies", options =>
            //    {
            //        options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
            //        options.SlidingExpiration = true;
            //    })
            //    .AddOpenIdConnect("oidc", options =>
            //    {
            //        options.SignInScheme = "ZfsoftCookies";

            //        options.Authority = "http://localhost:50876/";
            //        options.RequireHttpsMetadata = false;

            //        options.ClientId = "mvc";
            //        options.ClientSecret = "secret";
            //        options.ResponseType = "code id_token";

            //        options.SaveTokens = true;
            //        options.GetClaimsFromUserInfoEndpoint = true;

            //        options.Scope.Add("api1");
            //        //options.Scope.Add("role");
            //        options.Scope.Add("offline_access");
            //    });
            //services.AddAuthentication()
            //.AddGoogle("Google", options =>
            //{
            //    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

            //    options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
            //    options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
            //})
            //.AddOpenIdConnect("oidc", "OpenID Connect", options =>
            //{
            //    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
            //    options.SignOutScheme = IdentityServerConstants.SignoutScheme;

            //    options.Authority = "https://demo.identityserver.io/";
            //    options.ClientId = "implicit";

            //    options.TokenValidationParameters = new TokenValidationParameters
            //    {
            //        NameClaimType = "name",
            //        RoleClaimType = "role"
            //    };
            //});
        }
Пример #7
0
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using IdentityServer4;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace QuickstartIdentityServer
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
			services.AddIdentityServer()
				//.AddDeveloperSigningCredential()
				.AddSigningCredential(Certificate.GetCertificate())
				.AddInMemoryIdentityResources(Config.GetIdentityResources())
				.AddInMemoryApiResources(Config.GetApiResources())
				.AddInMemoryPersistedGrants()
				.AddInMemoryClients(Config.GetClients())
				.AddTestUsers(Config.GetUsers());

			services.AddAuthentication()
				.AddGoogle("Google", options =>
				{
					options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

					// register your IdentityServer with Google at https://console.developers.google.com
					// enable the Google+ API
					// set the redirect URI to http://localhost:port/signin-google
					options.ClientId = "copy client ID from Google here";
					options.ClientSecret = "copy client secret from Google here";
				})
				.AddOpenIdConnect("oidc", "OpenID Connect", options =>
				{
					options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
					options.SignOutScheme = IdentityServerConstants.SignoutScheme;

					options.Authority = "https://identity.buyingagentapp.com/";
					options.ClientId = "implicit";

					options.TokenValidationParameters = new TokenValidationParameters
					{
						NameClaimType = "name",
						RoleClaimType = "role"
					};
				});
		}

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
			else
			{
				app.UseExceptionHandler();
			}

			app.UseIdentityServer();

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
    }
}
Пример #8
0
        public void ConfigureServices(IServiceCollection services)
        {
            var migrationAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            services.AddMvc();

            services.AddAuthenticationCore(options =>
            {
                options.AddScheme <MyAuthenticationHandler>("myScheme", "demo scheme");
            });


            services.AddTransient <IExtensionGrantValidator, MyCrapGrantValidator>();

            services.AddAuthentication()
            .AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.ClientId     = "33f1f15d-93d5-4749-9b0e-24fc7c0bf56e";
                options.ClientSecret = "wttGKYI05[vppzBAG913#?_";
            })
            .AddOpenIdConnect("Extend", "OA账号登录", options =>
            {
                options.Authority     = "http://127.0.0.1:7000";
                options.SignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.SignOutScheme = IdentityServerConstants.SignoutScheme;
                // Configure the Client ID and Client Secret
                options.ClientId             = "ZnwqE8j-H6kmHeQBM3NH2WbdikUjPrNV";
                options.ClientSecret         = "jecyL0PrTIxjNf4GUbz0oa_ssRLiJBG8OXfIMzLDjGCEoTV48HHqvK2pasPodPyN";
                options.RequireHttpsMetadata = false;
                // Set response type to code
                options.ResponseType = "code";
                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.CallbackPath = new PathString("/callback");
                options.GetClaimsFromUserInfoEndpoint = true;
                // Configure the Claims Issuer
                options.ClaimsIssuer = "Extend";
                // Saves tokens to the AuthenticationProperties
                options.SaveTokens = true;
            });
            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer(options =>
            {
                options.Authentication.CookieLifetime          = TimeSpan.FromDays(1);
                options.Authentication.CookieSlidingExpiration = true;
            })
            //.AddDeveloperSigningCredential()
            .AddSigningCredential(new X509Certificate2("",
                                                       Configuration["Certificates:Password"]))
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            //.AddTestUsers(Config.GetUsers())

            //.AddConfigurationStore(options =>
            //{
            //    options.ConfigureDbContext = b =>
            //        b.UseSqlServer(connString,
            //            sql => sql.MigrationsAssembly(migrationAssembly));
            //})
            //.AddOperationalStore(options =>
            //{
            //    options.ConfigureDbContext = b =>
            //        b.UseSqlServer(connString,
            //            sql => sql.MigrationsAssembly(migrationAssembly));
            //})
            .AddExtensionGrantValidator <CzarCustomUserGrantValidator>()
            .AddProfileService <UserProfileService>();
            services.AddDbContext <CISDI_TEST20180829Context>(
                options => options.UseSqlServer(Configuration["ConnectionStrings"]));
            services.AddTransient <UserStore>();
        }