Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SagaBus sagaBus,
                              IOptions <OAuth20Configuration> oauthOptions)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = AuthenticationSchemes.OAuth20Cookie,
                AutomaticChallenge    = false,
                AutomaticAuthenticate = false
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = AuthenticationSchemes.PortalCookie,
                AutomaticChallenge    = false,
                AutomaticAuthenticate = false
            });

            var oauthConfig = oauthOptions.Value;
            var key         = oauthConfig.TokenSigningKey;
            var signingKey  = new SymmetricSecurityKey(Encoding.Unicode.GetBytes(key));
            var param       = new TokenValidationParameters
            {
                AuthenticationType       = "Bearer",
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = signingKey,
                ValidateIssuer           = true,
                ValidIssuer   = oauthConfig.TokenIssuer,
                ValidAudience = oauthConfig.TokenAudience
            };

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                TokenValidationParameters = param,
                AutomaticAuthenticate     = false,
                AutomaticChallenge        = false
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            MappingConfig.ConfigureQueryModelMapping();
            sagaBus.RegisterSagas();

            app.UseSwagger();
            app.UseSwaggerUi(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Obsidian API");
            });
        }