From 6e8ec037b9af8cc9c8c058276fbd1f4b1a117bab Mon Sep 17 00:00:00 2001 From: Nick Rirush Date: Thu, 7 Feb 2019 12:48:25 +0800 Subject: [PATCH] Add Antiforgery and Cookie Authentication --- Source/Startup.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Startup.cs b/Source/Startup.cs index 31e5268..1485131 100644 --- a/Source/Startup.cs +++ b/Source/Startup.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -30,6 +31,9 @@ namespace QuickCHAT options => options.UseNpgsql(Configuration.GetConnectionString("MainDatabase")) ) .BuildServiceProvider(); + services.AddAntiforgery(); + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + .AddCookie(options => options.LoginPath = new PathString("/authorize")); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -42,7 +46,7 @@ namespace QuickCHAT app.UseHsts(); app.UseHttpsRedirection(); } - + app.UseAuthentication(); app.UseMvc(); } }