예제 #1
0
파일: Startup.cs 프로젝트: byme8/Sample
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            DataBootstrap.Bootstrap();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "App.API v1"));
            }

            app.UseCors(o => o
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin());

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            LogicBootstrap.Bootstrap(services);
            DataBootstrap.Bootstrap(services);

            services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
            services.Configure <BarrierOptions>(options =>
            {
                options.SecurityKey       = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("51BDEAFE-C65E-4D72-86D9-35E46D19A5FF"));
                options.SecurityAlgorithm = SecurityAlgorithms.HmacSha256;
                options.Issuer            = "Local";
            });
            services.AddAuthentication()
            .AddFacebook("Facebook", opts =>
            {
                opts.AppId     = "564864066973412";
                opts.AppSecret = "770e2c75bf5434570f67a862bcc99ad1";
            })
            .AddJwtBearer("Bearer", options =>
            {
                options.SaveToken    = true;
                options.ClaimsIssuer = "Local";
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidIssuer              = "Local",
                    ValidateIssuerSigningKey = true,
                    ValidateAudience         = false,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("51BDEAFE-C65E-4D72-86D9-35E46D19A5FF")),
                };
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddUserManager <CustomUserManager>()
            .AddUserStore <CustomUserStore>()
            .AddRoleStore <CustomRoleStore>()
            .AddDefaultTokenProviders();
            services.AddTransient <IUserContextContainer, UserContextContainer>();

            services.AddMvc().AddJsonOptions(opts =>
            {
                opts.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
                opts.SerializerSettings.ContractResolver     = new DefaultContractResolver();
            });
        }