// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Configure DbContext //services.AddAbpDbContext<UcenterDbContext>(options => //{ // DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString); //}); services.AddDbContextPool <UcenterDbContext>(options => options.UseMySql(Configuration.GetConnectionString("Default"))); services.AddIdentityServer() .AddExtensionGrantValidator <SmsAuthCodeValidator>() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(Config.GetIdentityResourceResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()); //.AddResourceOwnerValidator<ResourceOwnerPasswordValidator>() //.AddProfileService<ProfileService>(); //从配置文件中获取ServiceDiscovery services.Configure <ServiceDisvoveryOptions>(Configuration.GetSection("ServiceDiscovery")); //单例注册ConsulClient services.AddSingleton <IDnsQuery>(p => { var serviceConfigration = p.GetRequiredService <IOptions <ServiceDisvoveryOptions> >().Value; return(new LookupClient(serviceConfigration.Consul.DnsEndpoint.ToIPEndPoint())); }); //注册全局单例ResilineceClientFactory services.AddSingleton(typeof(ResilineceClientFactory), sp => { var logger = sp.GetRequiredService <ILogger <ResilienceHttpClient> >(); var httpcontextAccesser = sp.GetRequiredService <IHttpContextAccessor>(); var retryCount = 5; var exceptionCountAllowedBeforeBreaking = 5; return(new ResilineceClientFactory(logger, httpcontextAccesser, retryCount, exceptionCountAllowedBeforeBreaking)); }); services.AddSingleton <IHttpClient>(sp => { return(sp.GetRequiredService <ResilineceClientFactory>().GetResilienceHttpClient()); }); services.AddScoped(typeof(UcenterDbContext)); services.AddScoped <IAuthService, AuthServce>(); services.AddScoped <IUserServise, UserService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// 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 https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetUsers()) .AddProfileService <AdditionalClaimsProfileService>() .AddDeveloperSigningCredential(); // use in memory for testing. services .AddDbContext <IdentityServerContext>(opt => opt.UseMySql(Configuration.GetConnectionString("MyConnectionString"))) //"Server=localhost;database=uow;uid=root;pwd=root1234;")) .AddUnitOfWork <IdentityServerContext>() .AddCustomRepository <User, UserRepository>(); services.AddMvc(); }
private static void InitializeDatabase(IApplicationBuilder app) { bool createdNewRepository = false; var repository = app.ApplicationServices.GetService <IRepository>(); // --Client if (!repository.CollectionExists <Client>()) { foreach (var client in Config.GetClients()) { repository.Add <Client>(client); } createdNewRepository = true; } // --IdentityResource if (!repository.CollectionExists <IdentityResource>()) { foreach (var res in Config.GetIdentityResources()) { repository.Add <IdentityResource>(res); } createdNewRepository = true; } // --ApiResource if (!repository.CollectionExists <ApiResource>()) { foreach (var api in Config.GetApiResources()) { repository.Add <ApiResource>(api); } createdNewRepository = true; } // If it's a new Repository (database), need to restart the website to configure Mongo to ignore Extra Elements. if (createdNewRepository) { var newRepositoryMsg = $"Mongo Repository created/populated! Please restart you website, so Mongo driver will be configured to ignore Extra Elements."; throw new Exception(newRepositoryMsg); } }
// 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 https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // 使用内存存储,密钥,客户端和资源来配置身份服务器。 services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) //添加api资源 .AddInMemoryClients(Config.GetClients()) //添加客户端 .AddTestUsers(Config.GetUsers()); //添加测试用户 services.AddAuthentication() .AddQQ(qq => { qq.AppId = "101543795"; qq.AppKey = "3dafebb5bd15c6cb4fe9144758898645"; }); }
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() .AddQQ(qqOptions => { qqOptions.AppId = "这里配置"; qqOptions.AppKey = "这里配置"; }); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //services.AddAuthentication() // .AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, options => // { // options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; // options.ClientId = "33f1f15d-93d5-4749-9b0e-24fc7c0bf56e"; // options.ClientSecret = "wttGKYI05[vppzBAG913#?_"; // }); // 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()); }
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() //options => { //options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; //options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; //}) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme) .AddGoogle("Google", options => { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; options.ClientId = "172986759996-f031j0mlqh8k9qgumm3h602cm5rt0595.apps.googleusercontent.com"; options.ClientSecret = "R4Rd84vx1Gab7cJo-bJhXl6v"; }) .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, "Azure Portal", options => { options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; options.ClientId = "415ee7f3-0c53-4c58-9579-3cf54c1fd63e"; // options.ClientSecret = "7KyCzTicUzgDuAL5wf/JGdM23bSEnCyBuwAwK6IxN3w="; options.Authority = $"https://login.microsoftonline.com/common"; options.ResponseType = OpenIdConnectResponseType.IdToken; options.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = "https://sts.windows.net/8d327499-ca18-4d3b-b150-24dfd1cbf5f5/", NameClaimType = "name", RoleClaimType = "role" }; }); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddMvc(); // configure identity server with in-memory stores, keys, clients and scopes services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetUsers()); }
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 = "113871300477-jiaci39qj3jcv1rmt9in6kpc1m8ml769.apps.googleusercontent.com"; options.ClientSecret = "rYrcx3ekWiqR6d35FqUQnMP2"; }); }
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 = "1005450161824-hqg5jq2qnplaskfnjcor4erfb5m8g0rs.apps.googleusercontent.com"; options.ClientSecret = "GPj_fCos-5jC1dhqNL3yCZjE"; }); }
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"; }); }
public void ConfigureServices(IServiceCollection services) { //services.AddCors(options => //{ // options.AddPolicy("AllowSpecificOrigin", // builder => builder.WithOrigins("http://example.com").AllowAnyHeader()); //}); services.AddMvc(options => { options.Filters.Add(new UrlReferrerFilter()); // an instance }); // configure identity server with in-memory stores, keys, clients and scopes services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()) .AddTestUsers(Config.GetUsers()) .AddProfileService <CustomProfileService>(); }
public static void EnsureSeedData(IServiceProvider serviceProvider) { Console.WriteLine("Seeding database..."); using (var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <IConfigurationMongoDbContext>(); var count = context.Client.Count(Builders <IdentityServer4.MongoDB.Models.Client> .Filter.Empty); if (count == 0) { foreach (var client in Config.GetClients().ToList()) { context.Client.InsertOne(client.ToEntity()); } } count = context.IdentityResource.Count(Builders <IdentityServer4.MongoDB.Models.IdentityResource> .Filter.Empty); if (count == 0) { foreach (var resource in Config.GetIdentityResources().ToList()) { context.IdentityResource.InsertOne(resource.ToEntity()); } } count = context.ApiResource.Count(Builders <IdentityServer4.MongoDB.Models.ApiResource> .Filter.Empty); if (count == 0) { foreach (var resource in Config.GetApiResources().ToList()) { context.ApiResource.InsertOne(resource.ToEntity()); } } } Console.WriteLine("Done seeding database."); Console.WriteLine(); }
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()) //.AddWsFederation() //.AddInMemoryRelyingParties(Config.GetRelyingParties()) ; 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" }; }); }
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; // 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://demo.identityserver.io/"; options.ClientId = "implicit"; options.TokenValidationParameters = new TokenValidationParameters { NameClaimType = "name", RoleClaimType = "role" }; }); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(); 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() .AddWsFederation(options => { options.Wtrealm = "https://priveravardgivaremikael.vgregion.se/"; options.MetadataAddress = "https://win-i5vs66s3gnb.priveramikael.com/federationmetadata/2007-06/federationmetadata.xml"; options.UseTokenLifetime = true; //options.CallbackPath = new PathString("/ExternalLoginCallback"); }); }
// 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(); } } }
// 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" // }; //}); }
// 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(); } } }
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>(); }