Added logout function + increased default openid config caching time

This commit is contained in:
2024-12-23 12:38:30 +01:00
parent 849ad649a8
commit 0b9766f7db
4 changed files with 8 additions and 6 deletions

View File

@@ -1,10 +1,7 @@
using HopFrame.Api.Models; using HopFrame.Api.Models;
using HopFrame.Security.Authentication.OpenID; using HopFrame.Security.Authentication.OpenID;
using HopFrame.Security.Authentication.OpenID.Options;
using HopFrame.Security.Claims; using HopFrame.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace HopFrame.Api.Controller; namespace HopFrame.Api.Controller;
@@ -63,8 +60,7 @@ public class OpenIdController(IOpenIdAccessor accessor) : ControllerBase {
[HttpDelete("logout")] [HttpDelete("logout")]
public IActionResult Logout() { public IActionResult Logout() {
Response.Cookies.Delete(ITokenContext.RefreshTokenType); accessor.Logout();
Response.Cookies.Delete(ITokenContext.AccessTokenType);
return Ok(); return Ok();
} }

View File

@@ -11,4 +11,5 @@ public interface IOpenIdAccessor {
Task<OpenIdIntrospection> InspectToken(string token); Task<OpenIdIntrospection> InspectToken(string token);
Task<OpenIdToken> RefreshAccessToken(string refreshToken); Task<OpenIdToken> RefreshAccessToken(string refreshToken);
void SetAuthenticationCookies(OpenIdToken token); void SetAuthenticationCookies(OpenIdToken token);
void Logout();
} }

View File

@@ -137,4 +137,9 @@ internal class OpenIdAccessor(IHttpClientFactory clientFactory, IOptions<OpenIdO
Secure = true Secure = true
}); });
} }
public void Logout() {
accessor.HttpContext!.Response.Cookies.Delete(ITokenContext.RefreshTokenType);
accessor.HttpContext!.Response.Cookies.Delete(ITokenContext.AccessTokenType);
}
} }

View File

@@ -22,7 +22,7 @@ public sealed class OpenIdOptions : OptionsFromConfiguration {
Configuration = new() { Configuration = new() {
Enabled = true, Enabled = true,
TTL = new() { TTL = new() {
Minutes = 10 Hours = 24
} }
}, },
Auth = new() { Auth = new() {