示例#1
0
        /// <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);
        }
示例#2
0
        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();
        }