/// <summary> /// /// </summary> /// <param name="services"></param> /// <param name="configuration"></param> /// <param name="env"></param> /// <returns></returns> public static IIdentityServerBuilder AddGroupyfyIdentityServer(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment env) { var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; var builder = services .AddIdentityServer() .AddAspNetIdentity <GroupyfyUser>() .AddInMemoryIdentityResources(ISConfig.GetIdentityResources()) .AddInMemoryClients(ISConfig.GetClients()) .AddInMemoryApiResources(ISConfig.GetApis(configuration)) .AddInMemoryPersistedGrants() .AddInMemoryCaching() .AddOperationalStore(options => { options.ConfigureDbContext = b => b.UseSqlServer(configuration.GetConnectionString("GroupyfySecurityDatabase"), db => db.MigrationsAssembly(migrationsAssembly)); }); services.AddTransient <IProfileService, GroupyfyProfileService>(); if (env.IsDevelopment()) { builder.AddDeveloperSigningCredential(); } return(builder); }
public void ConfigureServices(IServiceCollection services) { BusinessConfiguration config = services.AddSingletonConfiguration <BusinessConfiguration>(Configuration); services.AddSingletonConfiguration <PaymentConfiguration>(Configuration); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); services.AddDbContext <ApplicationDbContext>(optionsBuilder => optionsBuilder.UseMySql(Configuration["ConnectionString"]) ); services.AddCors(); services.AddMvc(options => { options.Filters.Add(new ValidationFailedExceptionFilter()); }); services.AddMvcCore().AddAuthorization(); services.AddHsts(options => { options.Preload = true; options.IncludeSubDomains = true; options.MaxAge = TimeSpan.FromDays(60); }); if (bool.TrueString == Configuration["UseHttpsRedirection"]) { services.AddHttpsRedirection(options => { options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect; options.HttpsPort = int.Parse(Configuration["https_port"]); }); } services.AddIdentityServer(options => options.IssuerUri = config.BaseAddress) .AddSigningCredential(new X509Certificate2(Configuration["SslCertificate"], Configuration["SslCertificatePassword"])) .AddValidationKey(new X509Certificate2(Configuration["SslCertificate"], Configuration["SslCertificatePassword"])) .AddInMemoryIdentityResources(ISConfig.GetIdentityResources()) .AddInMemoryApiResources(ISConfig.GetApiResources()) .AddInMemoryClients(ISConfig.GetClients()) .AddProfileService <CustomProfileService>() .AddResourceOwnerValidator <CustomResourceOwnerPasswordValidator>() .AddJwtBearerClientAuthentication(); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { options.Authority = config.IdentityServerUrl; options.ApiName = ISConfig.AuthScope; options.RequireHttpsMetadata = false; options.SupportedTokens = SupportedTokens.Jwt; }); services.AddDependencyInjection(); }
//private static Timer _timer; // 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.AddCors(); services .AddSignalR(options => { options.EnableDetailedErrors = true; }) .AddMessagePackProtocol(); services.AddMvcCore() .AddNewtonsoftJson() .AddAuthorization(); services.AddIdentityServer( options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseSuccessEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseInformationEvents = true; }) .AddInMemoryApiResources(ISConfig.GetApiResources()) .AddInMemoryApiScopes(ISConfig.GetApiScopes()) .AddTestUsers(ISConfig.GetUsers()) .AddInMemoryClients(ISConfig.GetClients()) //.AddSigningCredential(Cert.Get("theCert.pfx", "somePassword")) .AddDeveloperSigningCredential(); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { options.Authority = "https://localhost:5001/"; options.RequireHttpsMetadata = true; options.ApiName = "shortlivedchat"; options.TokenRetriever = new Func <HttpRequest, string>(req => { var fromAuthorizationHeader = TokenRetrieval.FromAuthorizationHeader(); var fromQueryString = TokenRetrieval.FromQueryString(); return(fromAuthorizationHeader(req) ?? fromQueryString(req)); }); IdentityModelEventSource.ShowPII = true; }); services.AddSingleton <GroupsManager>(); }