//Pasar como param los datos del clientID y Secret public void ConfigureServices(IServiceCollection services) { var rsa = new RsaKeyService(Environment, TimeSpan.FromDays(30)); services.AddTransient <RsaKeyService>(provider => rsa); var builder = services.AddIdentityServer() .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiScopes(Config.ApiScopes) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients()); Environment.Equals(false); if (Environment.IsDevelopment()) { builder.AddSigningCredential(rsa.GetKey(), IdentityServer4.IdentityServerConstants.RsaSigningAlgorithm.RS256); } else { builder.AddSigningCredential(rsa.GetKey(), IdentityServer4.IdentityServerConstants.RsaSigningAlgorithm.RS256); } }
public void ConfigureServices(IServiceCollection services) { services.AddScoped <IIdentityService, IdentityService>(); services.AddCors(options => { options.AddPolicy("AllowAllHeaders", builder => { builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddInfrastructure(Configuration); services.AddIdentity <IdentityUser, IdentityRole>(options => { options.Tokens.ProviderMap.Add("Default", new TokenProviderDescriptor(typeof(IUserTwoFactorTokenProvider <IdentityUser>))); }) .AddDefaultTokenProviders().AddEntityFrameworkStores <AppDbContext>(); var rsa = new RsaKeyService(Environment, TimeSpan.FromDays(30)); services.AddSingleton <RsaKeyService>(provider => rsa); var builder = services.AddIdentityServer(options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseInformationEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseSuccessEvents = true; // see https://identityserver4.readthedocs.io/en/latest/topics/resources.html options.EmitStaticAudienceClaim = true; }) .AddAspNetIdentity <IdentityUser>().AddProfileService <ProfileService>(); // in-memory, code config builder.AddInMemoryIdentityResources(ServerConfiguration.IdentityResources); builder.AddInMemoryApiScopes(ServerConfiguration.ApiScopes); builder.AddInMemoryClients(ServerConfiguration.Clients); builder.AddInMemoryApiResources(ServerConfiguration.ApiResources); // var rsaCertificate = new X509Certificate2(Path.Combine(Environment.ContentRootPath, "rsaCert.pfx"), "1234"); if (!Environment.IsDevelopment()) { builder.AddSigningCredential(rsa.GetKey(), RsaSigningAlgorithm.RS512); } if (Environment.IsDevelopment()) { builder.AddDeveloperSigningCredential(); } services.AddTransient <IEmailSender, EmailSender>(i => new EmailSender( Configuration["EmailSender:Host"], Configuration.GetValue <int>("EmailSender:Port"), Configuration.GetValue <bool>("EmailSender:EnableSSL"), Configuration["EmailSender:UserName"], Configuration["EmailSender:Password"] ) ); services.AddControllersWithViews(); services.AddRazorPages(); }