示例#1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.ConfigureRootConfiguration(Configuration);

            ///// Add single tenant configuration
            services.AddSingleTenantConfiguration(Configuration, Environment, Logger,
                                                  StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityOptions(),
                                                  StartupHelpers.DefaultIdentityServerOptions(),
                                                  StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration)
                                                  );

            /// Add multi tenant configuration
            /// Seeding data requires that you build the identity migration using the <see cref="MultiTenantUserIdentityDbContext"/>
            /// The _layout page requires the SignInManager to have the type specified to use the <see cref="MultiTenantUserIdentity"/>
            //services.AddMultiTenantConfiguration(Configuration, Environment, Logger,
            //    StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
            //    StartupHelpers.DefaultIdentityOptions(),
            //    StartupHelpers.DefaultIdentityServerOptions(),
            //    StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
            //    StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration)
            //    );

            // Add email senders which is currently setup for SendGrid and SMTP
            services.AddEmailSenders(Configuration);

            // Add services for authentication, including Identity model, IdentityServer4 and external providers
            services.AddAuthenticationServices(Configuration);

            // Add authorization policies for MVC
            services.AddAuthorizationPolicies();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            // Get Configuration
            services.ConfigureRootConfiguration(Configuration);
            var rootConfiguration = services.BuildServiceProvider().GetService <IRootConfiguration>();

            ///// Manual configuration
            //services
            //    .AddCustomConfiguration
            //        <AdminIdentityDbContext, IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext>
            //        (HostingEnvironment,
            //        StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
            //        StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
            //        StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration),
            //        StartupHelpers.DefaultLogDbContextOptions(Configuration))
            //    .AddCustomIdentity
            //        <AdminIdentityDbContext, UserIdentity, UserIdentityRole>
            //        (StartupHelpers.DefaultIdentityOptions(Configuration))
            //    .AddCustomAdminAspNetIdentityServices
            //        <AdminIdentityDbContext, IdentityServerPersistedGrantDbContext, UserDto<string>, string, RoleDto<string>, string, string, string,
            //        UserIdentity, UserIdentityRole, string, UserIdentityUserClaim, UserIdentityUserRole,
            //        UserIdentityUserLogin, UserIdentityRoleClaim, UserIdentityUserToken,
            //        UsersDto<UserDto<string>, string>, RolesDto<RoleDto<string>, string>, UserRolesDto<RoleDto<string>, string, string>,
            //        UserClaimsDto<string>, UserProviderDto<string>, UserProvidersDto<string>, UserChangePasswordDto<string>,
            //        RoleClaimsDto<string>, UserClaimDto<string>, RoleClaimDto<string>>();

            ///// Single tenant configuration (default)
            services.AddSingleTenantConfiguration(HostingEnvironment,
                                                  StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration),
                                                  StartupHelpers.DefaultLogDbContextOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityOptions(Configuration));

            /// Multi Tenant configuration
            //services.AddMultiTenantConfiguration(HostingEnvironment,
            //    StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
            //    StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
            //    StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration),
            //    StartupHelpers.DefaultLogDbContextOptions(Configuration),
            //    StartupHelpers.DefaultIdentityOptions(Configuration));

            // Add Asp.Net Core Identity Configuration and OpenIdConnect auth as well
            services.AddAuthenticationServices(HostingEnvironment, rootConfiguration.AdminConfiguration);

            // Add exception filters in MVC
            services.AddMvcExceptionFilters();

            // Add authorization policies for MVC
            services.AddAuthorizationPolicies();

            services.Configure <SeedData>(Configuration.GetSection(ConfigurationConsts.SeedDataConfigurationKey));
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var adminApiConfiguration = Configuration.GetSection(nameof(AdminApiConfiguration)).Get <AdminApiConfiguration>();

            services.AddSingleton(adminApiConfiguration);

            ///// Single Tenant configuration
            services.AddSingleTenantConfiguration(HostingEnvironment,
                                                  StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration),
                                                  StartupHelpers.DefaultLogDbContextOptions(Configuration),
                                                  StartupHelpers.DefaultIdentityOptions(Configuration));

            /// Multi Tenant configuration
            //services.AddMultiTenantConfiguration(HostingEnvironment,
            //    StartupHelpers.DefaultIdentityDbContextOptions(Configuration),
            //    StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration),
            //    StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration),
            //    StartupHelpers.DefaultLogDbContextOptions(Configuration),
            //    StartupHelpers.DefaultIdentityOptions(Configuration));

            //services.AddDbContexts<AdminIdentityDbContext, IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext>(Configuration);
            services.AddScoped <ControllerExceptionFilterAttribute>();

            services.AddApiAuthentication(adminApiConfiguration);
            services.AddAuthorizationPolicies();

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc(ApiConfigurationConsts.ApiVersionV1, new Info {
                    Title = ApiConfigurationConsts.ApiName, Version = ApiConfigurationConsts.ApiVersionV1
                });

                options.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Flow             = "implicit",
                    AuthorizationUrl = $"{adminApiConfiguration.IdentityServerBaseUrl}/connect/authorize",
                    Scopes           = new Dictionary <string, string> {
                        { adminApiConfiguration.OidcApiName, ApiConfigurationConsts.ApiName }
                    }
                });

                options.OperationFilter <AuthorizeCheckOperationFilter>();
            });
        }