-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApplicationsController.cs
More file actions
69 lines (62 loc) · 2.69 KB
/
Copy pathApplicationsController.cs
File metadata and controls
69 lines (62 loc) · 2.69 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
58
59
60
61
62
63
64
65
66
67
68
69
using redb.Identity.Contracts.Applications;
using redb.Identity.Contracts.Common;
using redb.Identity.Contracts.Routes;
using redb.Route.Controllers.Attributes;
namespace redb.Identity.Http.Controllers;
/// <summary>
/// REST management API for OAuth 2.0 applications (clients).
/// Forwards to <c>direct-vm://identity-manage-apps</c> route.
/// </summary>
[Route("applications")]
public class ApplicationsController : IdentityControllerBase
{
[HttpGet]
public async Task<object?> List(
[FromQuery("offset")] int offset = 0,
[FromQuery("count")] int count = 25)
{
return await Forward(IdentityEndpoints.ManageApps, "list",
new ListRequest { Offset = offset, Count = count });
}
[HttpGet("{id}")]
public async Task<object?> Get([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageApps, "read", ParseIdBody(id, stringKey: "clientId"));
}
[HttpPost]
public async Task<object?> Create([FromBody] CreateApplicationRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
return await Forward(IdentityEndpoints.ManageApps, "create", request);
}
[HttpPut("{id}")]
public async Task<object?> Update([FromRoute("id")] string id, [FromBody] UpdateApplicationRequest request)
{
request.Id = id;
if (ValidateRequest(request) is { } problem) return problem;
return await Forward(IdentityEndpoints.ManageApps, "update", request);
}
/// <summary>
/// Rotates the <c>client_secret</c> of a confidential OAuth application. Returns the
/// new plaintext secret <b>once</b> in the response body; subsequent reads will not
/// expose it (only BCrypt hash is stored). The previous secret is invalidated
/// immediately — any client_credentials/refresh flow holding the old value will get
/// 401 from the next call onward.
/// <para>
/// Declared before <see cref="Delete"/> so that the literal <c>rotate-secret</c>
/// segment cannot be swallowed by the <c>{id}</c> template (the <c>id</c> would
/// otherwise contain the slash). <c>ControllerRegistry</c> also prefers literal
/// over template during resolution; the ordering is belt-and-braces protection.
/// </para>
/// </summary>
[HttpPost("{id}/rotate-secret")]
public async Task<object?> RotateSecret([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageApps, "rotate-secret", ParseIdBody(id));
}
[HttpDelete("{id}")]
public async Task<object?> Delete([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageApps, "delete", ParseIdBody(id, stringKey: "clientId"));
}
}