-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLogout.cs
More file actions
29 lines (25 loc) · 899 Bytes
/
Logout.cs
File metadata and controls
29 lines (25 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using OpenShock.Common.Options;
using OpenShock.Common.Services.Session;
using OpenShock.Common.Utils;
namespace OpenShock.API.Controller.Account;
public sealed partial class AccountController
{
[HttpPost("logout")]
[ProducesResponseType(StatusCodes.Status200OK)]
[MapToApiVersion("1")]
public async Task<IActionResult> Logout([FromServices] ISessionService sessionService)
{
// Remove session if valid
if (HttpContext.TryGetUserSessionToken(out var sessionToken))
{
await sessionService.DeleteSessionByTokenAsync(sessionToken);
}
// Make sure cookie is removed, no matter if authenticated or not
RemoveSessionKeyCookie();
// its always a success, logout endpoints should be idempotent
return Ok();
}
}