Beispiel #1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = AuthentificationClass.Cookie;
                options.DefaultChallengeScheme = AuthentificationClass.OpenIdConnected;
            })
            .AddCookie(AuthentificationClass.Cookie)
            .AddOpenIdConnect(AuthentificationClass.OpenIdConnected,
                              options =>
            {
                options.Authority            = "https://localhost:49737";
                options.ClientId             = "hostClient";
                options.RequireHttpsMetadata = false;
                options.SignInScheme         = AuthentificationClass.Cookie;
                options.ResponseType         = "id_token";
                options.SaveTokens           = true;
            });

            // MVC
            services.AddMvc(
                options => options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName))
                );

            IdentityRegistrar.Register(services);
            AuthConfigurer.Configure(services, _appConfiguration);

            services.AddSignalR();

            // Configure CORS for angular2 UI
            services.AddCors(
                options => options.AddPolicy(
                    _defaultCorsPolicyName,
                    builder => builder
                    .WithOrigins(
                        // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                        _appConfiguration["App:CorsOrigins"]
                        .Split(",", StringSplitOptions.RemoveEmptyEntries)
                        .Select(o => o.RemovePostFix("/"))
                        .ToArray()
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials()

                    )
                );

            // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info {
                    Title = "TestProject API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);

                // Define the BearerAuth scheme that's in use
                options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });
            });

            // Configure Abp and Dependency Injection
            return(services.AddAbp <TestProjectWebHostModule>(
                       // Configure Log4Net logging
                       options => options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                           f => f.UseAbpLog4Net().WithConfig("log4net.config")
                           )
                       ));
        }