summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Program.cs1
-rw-r--r--Services/UserService.cs8
2 files changed, 8 insertions, 1 deletions
diff --git a/Program.cs b/Program.cs
index 01b7949..d8aa5c6 100644
--- a/Program.cs
+++ b/Program.cs
@@ -7,6 +7,7 @@ namespace HyperBooru;
public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);
+ builder.Services.AddAuthentication().AddCookie();
builder.Services.AddHttpContextAccessor();
builder.Services.AddControllers().AddJsonOptions(o => {
var converter = new JsonStringEnumConverter();
diff --git a/Services/UserService.cs b/Services/UserService.cs
index db62553..96f5b5f 100644
--- a/Services/UserService.cs
+++ b/Services/UserService.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authentication.Cookies;
using System.Runtime.InteropServices;
using System.Security.Claims;
using System.Security.Principal;
@@ -42,7 +43,9 @@ public class UserService : IUserService {
var claims = new Claim[] {
};
- var claimsIdentity = new ClaimsIdentity(claims);
+ var claimsIdentity = new ClaimsIdentity(
+ claims,
+ CookieAuthenticationDefaults.AuthenticationScheme);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
@@ -57,5 +60,8 @@ public class UserService : IUserService {
}
public void Logout() {
+ httpContextAccessor.HttpContext?.SignOutAsync()
+ .GetAwaiter()
+ .GetResult();
}
}