-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSessionsController.cs
More file actions
57 lines (52 loc) · 2.16 KB
/
Copy pathSessionsController.cs
File metadata and controls
57 lines (52 loc) · 2.16 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using redb.Identity.Contracts.Routes;
using redb.Route.Controllers.Attributes;
namespace redb.Identity.Http.Controllers;
[Route("sessions")]
public class SessionsController : IdentityControllerBase
{
[HttpGet]
public async Task<object?> List(
[FromQuery("userId")] string? userId = null,
[FromQuery("offset")] string? offset = null,
[FromQuery("count")] string? count = null)
{
// userId omitted → admin-wide browse of active sessions (WSO2-style
// default view, paginated). userId present → targeted per-user list.
if (string.IsNullOrEmpty(userId))
{
return await Forward(IdentityEndpoints.ManageSessions, "list-all",
new Dictionary<string, object?>
{
["offset"] = long.TryParse(offset, out var o) ? o : 0,
["count"] = long.TryParse(count, out var c) ? c : 25
});
}
return await Forward(IdentityEndpoints.ManageSessions, "list",
new Dictionary<string, object?> { ["userId"] = long.TryParse(userId, out var id) ? id : 0 });
}
[HttpDelete]
public async Task<object?> Revoke([FromQuery("sessionId")] string sessionId)
{
return await Forward(IdentityEndpoints.ManageSessions, "revoke",
new Dictionary<string, object?> { ["sessionId"] = long.TryParse(sessionId, out var id) ? id : 0 });
}
[HttpDelete("all")]
public async Task<object?> RevokeAll(
[FromQuery("userId")] string userId,
[FromQuery("dryRun")] string? dryRun = null)
{
var body = new Dictionary<string, object?>
{
["userId"] = long.TryParse(userId, out var id) ? id : 0
};
if (bool.TryParse(dryRun, out var dr) && dr)
body["dryRun"] = true;
return await Forward(IdentityEndpoints.ManageSessions, "revoke-all", body);
}
[HttpPost("logout")]
public async Task<object?> Logout([FromQuery("userId")] string userId)
{
return await Forward(IdentityEndpoints.ManageSessions, "logout",
new Dictionary<string, object?> { ["userId"] = long.TryParse(userId, out var id) ? id : 0 });
}
}