コード例 #1
0
ファイル: Startup.cs プロジェクト: antboj/TestProject
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // GitLab Test 2
            // 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);
                // Work with postman
                // application/x-www-form-urlencoded request or raw text request
                // grant_type=password&username=example&password=example&client_id=example&client_secret=example
                options.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type             = "oauth2",
                    Flow             = "password",
                    AuthorizationUrl = "http://localhost:60087/connect/authorize",
                    TokenUrl         = "http://localhost:60087/connect/token",
                    Scopes           = new Dictionary <string, string>
                    {
                        { "deviceApi", "Device API" }
                    }
                });
            });

            // Configure Abp and Dependency Injection
            return(services.AddAbp <TestProjectWebHostModule>(
                       // Configure Log4Net logging
                       options => options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                           f => f.UseAbpLog4Net().WithConfig("log4net.config")
                           )
                       ));
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: dejanjaredic/TestProject
        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")
                           )
                       ));
        }