| | | 1 | | using ArturRios.Heimdall.Shared.Security; |
| | | 2 | | using ArturRios.Util.WebApi.Security.Extensions; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.WebApi.Security; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Bridges the authenticated caller on the request to the actor-scoped commands and queries whose |
| | | 8 | | /// authorization depends on who is acting. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class ActorExtensions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Copies the authenticated caller (attached to the request by the auth middleware) onto an |
| | | 14 | | /// actor-scoped command or query, so the handler can enforce scope-scoped authorization |
| | | 15 | | /// (UC-02 AF-02b, UC-06 AF-06e, UC-07 AF-07b). The acting fields are always taken from the |
| | | 16 | | /// token, never from the request. |
| | | 17 | | /// </summary> |
| | | 18 | | public static void ApplyActor(this HttpContext httpContext, IActorScoped actorScoped) |
| | | 19 | | { |
| | 615 | 20 | | var actor = httpContext.GetUser<IdentityUser>()!; |
| | | 21 | | |
| | 615 | 22 | | actorScoped.ActingPersonId = actor.Id; |
| | 615 | 23 | | actorScoped.ActingRole = actor.RoleId; |
| | 615 | 24 | | } |
| | | 25 | | } |