Added logout function + increased default openid config caching time
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user