diff --git a/src/Heimdall.Web/Controllers/AgentsController.cs b/src/Heimdall.Web/Controllers/AgentsController.cs index d982e38..3e002d0 100644 --- a/src/Heimdall.Web/Controllers/AgentsController.cs +++ b/src/Heimdall.Web/Controllers/AgentsController.cs @@ -69,7 +69,7 @@ public class AgentsController : ControllerBase } /// Get agent details (JWT auth). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet("{id:guid}")] [ProducesResponseType(typeof(AgentResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -82,7 +82,7 @@ public class AgentsController : ControllerBase } /// List agents for a site. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet("by-site/{siteId:guid}")] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -96,7 +96,7 @@ public class AgentsController : ControllerBase } /// List all agents across all sites. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] diff --git a/src/Heimdall.Web/Controllers/AssignmentsController.cs b/src/Heimdall.Web/Controllers/AssignmentsController.cs index 98f488e..354c24e 100644 --- a/src/Heimdall.Web/Controllers/AssignmentsController.cs +++ b/src/Heimdall.Web/Controllers/AssignmentsController.cs @@ -25,7 +25,7 @@ namespace Heimdall.Api.Controllers; [ApiController] [Route("api/assignments")] [EnableRateLimiting("Api")] -[Authorize(AuthenticationSchemes = "JwtBearer")] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] public class AssignmentsController : ControllerBase { private readonly IMediator _mediator; @@ -79,7 +79,7 @@ public class AssignmentsController : ControllerBase } /// Get the active assignment for a camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("camera/{cameraId:guid}")] [ProducesResponseType(typeof(AssignmentResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -93,7 +93,7 @@ public class AssignmentsController : ControllerBase } /// Get all active assignments (workload) for an agent. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("agent/{agentId:guid}")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task GetAgentAssignments(Guid agentId, CancellationToken ct) @@ -103,7 +103,7 @@ public class AssignmentsController : ControllerBase } /// Get assignment history for a camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("camera/{cameraId:guid}/history")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task GetCameraHistory(Guid cameraId, CancellationToken ct) diff --git a/src/Heimdall.Web/Controllers/AuditLogsController.cs b/src/Heimdall.Web/Controllers/AuditLogsController.cs index f920494..69aebd2 100644 --- a/src/Heimdall.Web/Controllers/AuditLogsController.cs +++ b/src/Heimdall.Web/Controllers/AuditLogsController.cs @@ -10,7 +10,7 @@ namespace Heimdall.Api.Controllers; [ApiController] [Route("api/audit-logs")] -[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [EnableRateLimiting("Api")] public class AuditLogsController : ControllerBase { diff --git a/src/Heimdall.Web/Controllers/AuthController.cs b/src/Heimdall.Web/Controllers/AuthController.cs index c4f233a..0b4b7aa 100644 --- a/src/Heimdall.Web/Controllers/AuthController.cs +++ b/src/Heimdall.Web/Controllers/AuthController.cs @@ -120,7 +120,7 @@ public class AuthController : ControllerBase } /// Change the current user's password. - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [HttpPost("change-password")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -150,7 +150,7 @@ public class AuthController : ControllerBase } /// Register an admin user. Requires Admin role + feature flag auth.admin-registration.enabled. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = "AdminUsers")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = "AdminUsers")] [HttpPost("register-admin")] [ProducesResponseType(typeof(AuthResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -172,7 +172,7 @@ public class AuthController : ControllerBase } /// Enable 2FA for the current user. Returns the shared key and QR code URI for setup. - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [HttpPost("2fa/enable")] [ProducesResponseType(typeof(Enable2faResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -199,7 +199,7 @@ public class AuthController : ControllerBase } /// Disable 2FA for the current user. - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [HttpPost("2fa/disable")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -281,7 +281,7 @@ public class AuthController : ControllerBase } /// Logout — revoke the current refresh token. - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [HttpPost("logout")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task Logout([FromBody] LogoutRequest request, CancellationToken ct) diff --git a/src/Heimdall.Web/Controllers/CamerasController.cs b/src/Heimdall.Web/Controllers/CamerasController.cs index c77c5bb..f4c3c03 100644 --- a/src/Heimdall.Web/Controllers/CamerasController.cs +++ b/src/Heimdall.Web/Controllers/CamerasController.cs @@ -22,7 +22,7 @@ public class CamerasController : ControllerBase public CamerasController(IMediator mediator) => _mediator = mediator; /// Create a new camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost] [ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -36,7 +36,7 @@ public class CamerasController : ControllerBase } /// Get a camera by ID. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("{id:guid}")] [ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -49,7 +49,7 @@ public class CamerasController : ControllerBase } /// List cameras by site. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("by-site/{siteId:guid}")] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -63,7 +63,7 @@ public class CamerasController : ControllerBase } /// Update a camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPut("{id:guid}")] [ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -78,7 +78,7 @@ public class CamerasController : ControllerBase } /// Delete a camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpDelete("{id:guid}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] diff --git a/src/Heimdall.Web/Controllers/DiscoveryController.cs b/src/Heimdall.Web/Controllers/DiscoveryController.cs index ae23ab5..3931334 100644 --- a/src/Heimdall.Web/Controllers/DiscoveryController.cs +++ b/src/Heimdall.Web/Controllers/DiscoveryController.cs @@ -24,7 +24,7 @@ namespace Heimdall.Api.Controllers; /// [ApiController] [Route("api/discovery")] -[Authorize(AuthenticationSchemes = "JwtBearer")] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [EnableRateLimiting("Api")] public class DiscoveryController : ControllerBase { @@ -36,7 +36,7 @@ public class DiscoveryController : ControllerBase } /// Probe a single IP address for camera services. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost("probe")] [ProducesResponseType(typeof(ProbeResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -50,7 +50,7 @@ public class DiscoveryController : ControllerBase } /// Scan a subnet for camera devices. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost("scan")] [ProducesResponseType(typeof(IReadOnlyList), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -64,7 +64,7 @@ public class DiscoveryController : ControllerBase } /// Search the built-in camera database by brand, model, or preset. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("search")] [ProducesResponseType(typeof(SearchResponse), StatusCodes.Status200OK)] public async Task SearchDatabase([FromQuery] string? q, CancellationToken ct) @@ -74,7 +74,7 @@ public class DiscoveryController : ControllerBase } /// Build stream URLs from camera database entries. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpPost("build-urls")] [ProducesResponseType(typeof(StreamBuildResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -88,7 +88,7 @@ public class DiscoveryController : ControllerBase } /// Test stream URLs. Returns a session ID for polling. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost("test-streams")] [ProducesResponseType(typeof(StreamTestSession), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -102,7 +102,7 @@ public class DiscoveryController : ControllerBase } /// Poll a stream test session for updated results. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("test/{sessionId:guid}")] [ProducesResponseType(typeof(StreamTestSession), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -115,7 +115,7 @@ public class DiscoveryController : ControllerBase } /// Get a screenshot from a stream test session. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("test/{sessionId:guid}/screenshot/{index}")] [ProducesResponseType(typeof(byte[]), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -128,7 +128,7 @@ public class DiscoveryController : ControllerBase } /// Cancel a running stream test session. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost("test/{sessionId:guid}/cancel")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -141,7 +141,7 @@ public class DiscoveryController : ControllerBase } /// Check if a camera already exists for this IP/MAC (anti-duplication). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpPost("check")] [ProducesResponseType(typeof(CameraCheckResponse), StatusCodes.Status200OK)] public async Task CheckDuplicate([FromBody] CheckDuplicateRequest request, CancellationToken ct) @@ -152,7 +152,7 @@ public class DiscoveryController : ControllerBase } /// Confirm a discovery result and create a Camera entity. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpPost("confirm")] [ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(CameraCheckResponse), StatusCodes.Status409Conflict)] diff --git a/src/Heimdall.Web/Controllers/EventsController.cs b/src/Heimdall.Web/Controllers/EventsController.cs index 98ca01e..06a3628 100644 --- a/src/Heimdall.Web/Controllers/EventsController.cs +++ b/src/Heimdall.Web/Controllers/EventsController.cs @@ -42,7 +42,7 @@ public class EventsController : ControllerBase } /// Get a single event by ID. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("{id:guid}")] [ProducesResponseType(typeof(CameraEventResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -55,7 +55,7 @@ public class EventsController : ControllerBase } /// Query events with filters. Supports pagination. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] public async Task Query( @@ -79,7 +79,7 @@ public class EventsController : ControllerBase } /// Get recent events for a camera. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)] [HttpGet("camera/{cameraId:guid}")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task GetRecentByCamera(Guid cameraId, [FromQuery] int count = 20, CancellationToken ct = default) @@ -102,7 +102,7 @@ public class EventsController : ControllerBase } /// Delete an event. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.CameraWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)] [HttpDelete("{id:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] diff --git a/src/Heimdall.Web/Controllers/GroupsController.cs b/src/Heimdall.Web/Controllers/GroupsController.cs index 9b74cb8..b0ac91a 100644 --- a/src/Heimdall.Web/Controllers/GroupsController.cs +++ b/src/Heimdall.Web/Controllers/GroupsController.cs @@ -20,7 +20,7 @@ namespace Heimdall.Api.Controllers; /// [ApiController] [Route("api/groups")] -[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [EnableRateLimiting("Api")] public class GroupsController : ControllerBase { diff --git a/src/Heimdall.Web/Controllers/NotificationsController.cs b/src/Heimdall.Web/Controllers/NotificationsController.cs index fd0075b..e1ef067 100644 --- a/src/Heimdall.Web/Controllers/NotificationsController.cs +++ b/src/Heimdall.Web/Controllers/NotificationsController.cs @@ -20,7 +20,7 @@ namespace Heimdall.Web.Controllers; [ApiController] [Route("api/notifications")] [EnableRateLimiting("Api")] -[Authorize(AuthenticationSchemes = "JwtBearer")] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] public class NotificationsController : ControllerBase { private readonly IMediator _mediator; diff --git a/src/Heimdall.Web/Controllers/PermissionsController.cs b/src/Heimdall.Web/Controllers/PermissionsController.cs index 095f3a0..82bde9b 100644 --- a/src/Heimdall.Web/Controllers/PermissionsController.cs +++ b/src/Heimdall.Web/Controllers/PermissionsController.cs @@ -13,7 +13,7 @@ public record PermissionsListResponse(IReadOnlyList Permissions) [ApiController] [Route("api/permissions")] -[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [EnableRateLimiting("Api")] public class PermissionsController : ControllerBase { diff --git a/src/Heimdall.Web/Controllers/PersonsController.cs b/src/Heimdall.Web/Controllers/PersonsController.cs index 204974b..523a3ea 100644 --- a/src/Heimdall.Web/Controllers/PersonsController.cs +++ b/src/Heimdall.Web/Controllers/PersonsController.cs @@ -24,7 +24,7 @@ public class PersonsController : ControllerBase public PersonsController(IMediator mediator) => _mediator = mediator; - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonWrite)] [HttpPost] public async Task Create([FromBody] CreatePersonRequest request, CancellationToken ct) { @@ -33,7 +33,7 @@ public class PersonsController : ControllerBase return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error }); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonWrite)] [HttpPut("{id:guid}")] public async Task Update(Guid id, [FromBody] UpdatePersonRequest request, CancellationToken ct) { @@ -42,7 +42,7 @@ public class PersonsController : ControllerBase return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error }); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonRead)] [HttpGet("{id:guid}")] public async Task GetById(Guid id, CancellationToken ct) { @@ -50,7 +50,7 @@ public class PersonsController : ControllerBase return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error }); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonRead)] [HttpGet] public async Task GetAll([FromQuery] string? category, CancellationToken ct) { @@ -58,7 +58,7 @@ public class PersonsController : ControllerBase return Ok(result.Data); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonWrite)] [HttpDelete("{id:guid}")] public async Task Delete(Guid id, CancellationToken ct) { @@ -66,7 +66,7 @@ public class PersonsController : ControllerBase return result.IsSuccess ? Ok() : StatusCode(result.StatusCode ?? 404, new { error = result.Error }); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonWrite)] [HttpPost("{personId:guid}/faces")] public async Task RegisterFace(Guid personId, [FromBody] RegisterFaceRequest request, CancellationToken ct) { @@ -75,7 +75,7 @@ public class PersonsController : ControllerBase return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error }); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonRead)] [HttpGet("{personId:guid}/faces")] public async Task GetFaces(Guid personId, CancellationToken ct) { @@ -83,7 +83,7 @@ public class PersonsController : ControllerBase return Ok(result.Data); } - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.PersonWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.PersonWrite)] [HttpDelete("faces/{faceId:guid}")] public async Task DeleteFace(Guid faceId, CancellationToken ct) { diff --git a/src/Heimdall.Web/Controllers/RolesController.cs b/src/Heimdall.Web/Controllers/RolesController.cs index f356e29..570a3e0 100644 --- a/src/Heimdall.Web/Controllers/RolesController.cs +++ b/src/Heimdall.Web/Controllers/RolesController.cs @@ -13,7 +13,7 @@ public record RolesListResponse(IReadOnlyList Roles); [ApiController] [Route("api/roles")] -[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [EnableRateLimiting("Api")] public class RolesController : ControllerBase { diff --git a/src/Heimdall.Web/Controllers/SettingsController.cs b/src/Heimdall.Web/Controllers/SettingsController.cs index 4da0759..bb8c5df 100644 --- a/src/Heimdall.Web/Controllers/SettingsController.cs +++ b/src/Heimdall.Web/Controllers/SettingsController.cs @@ -21,7 +21,7 @@ namespace Heimdall.Api.Controllers; [ApiController] [Route("api/settings")] -[Authorize(AuthenticationSchemes = "JwtBearer")] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [EnableRateLimiting("Api")] public class SettingsController : ControllerBase { @@ -40,7 +40,7 @@ public class SettingsController : ControllerBase } /// List all global settings (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpGet] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] @@ -60,7 +60,7 @@ public class SettingsController : ControllerBase } /// Get a global setting by key (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpGet("{key}")] [ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -80,7 +80,7 @@ public class SettingsController : ControllerBase } /// Create a new global setting (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpPost] [ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -99,7 +99,7 @@ public class SettingsController : ControllerBase } /// Update a global setting (Admin only). Broadcasts the change to all agents. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpPut("{key}")] [ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -118,7 +118,7 @@ public class SettingsController : ControllerBase } /// Delete a global setting (Admin only). Broadcasts the change to all agents. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpDelete("{key}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -138,7 +138,7 @@ public class SettingsController : ControllerBase /// Get the effective configuration for an agent: global defaults merged with /// per-agent overrides (Agent or Admin only). /// - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpGet("agent/{agentId:guid}")] [ProducesResponseType(typeof(Dictionary), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -151,7 +151,7 @@ public class SettingsController : ControllerBase } /// List all setting overrides for a specific agent (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpGet("agent/{agentId:guid}/overrides")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -167,7 +167,7 @@ public class SettingsController : ControllerBase /// Set (create or update) a per-agent setting override (Admin only). /// Broadcasts the change to the affected agent in real-time. /// - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpPut("agent/{agentId:guid}/overrides")] [ProducesResponseType(typeof(AgentSettingDto), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -190,7 +190,7 @@ public class SettingsController : ControllerBase /// Remove a per-agent setting override (Admin only). /// Broadcasts a reload notification to the affected agent. /// - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpDelete("agent/{agentId:guid}/overrides/{key}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -210,7 +210,7 @@ public class SettingsController : ControllerBase /// Broadcast a "ConfigReload" signal to all connected agents so they /// re-fetch their full configuration (Admin only). /// - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminManage)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)] [HttpPost("reload")] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] diff --git a/src/Heimdall.Web/Controllers/SitesController.cs b/src/Heimdall.Web/Controllers/SitesController.cs index 4d5a1e4..d644a7b 100644 --- a/src/Heimdall.Web/Controllers/SitesController.cs +++ b/src/Heimdall.Web/Controllers/SitesController.cs @@ -24,7 +24,7 @@ public class SitesController : ControllerBase public SitesController(IMediator mediator) => _mediator = mediator; /// Create a new site (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteWrite)] [HttpPost] [ProducesResponseType(typeof(SiteWithTokenResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] @@ -43,7 +43,7 @@ public class SitesController : ControllerBase } /// List all sites. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] @@ -57,7 +57,7 @@ public class SitesController : ControllerBase } /// Get a site by ID. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet("{id:guid}")] [ProducesResponseType(typeof(SiteResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -70,7 +70,7 @@ public class SitesController : ControllerBase } /// Update a site (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteWrite)] [HttpPut("{id:guid}")] [ProducesResponseType(typeof(SiteResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -86,7 +86,7 @@ public class SitesController : ControllerBase } /// Delete a site (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteDelete)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteDelete)] [HttpDelete("{id:guid}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -100,7 +100,7 @@ public class SitesController : ControllerBase } /// Generate a new agent registration token (Admin only). - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteWrite)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteWrite)] [HttpPost("{id:guid}/tokens")] [ProducesResponseType(typeof(RegistrationTokenResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] diff --git a/src/Heimdall.Web/Controllers/StatsController.cs b/src/Heimdall.Web/Controllers/StatsController.cs index bd6490a..92ca238 100644 --- a/src/Heimdall.Web/Controllers/StatsController.cs +++ b/src/Heimdall.Web/Controllers/StatsController.cs @@ -19,7 +19,7 @@ public class StatsController : ControllerBase public StatsController(IMediator mediator) => _mediator = mediator; /// Get system-wide statistics. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet] [ProducesResponseType(typeof(StatsResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] @@ -32,7 +32,7 @@ public class StatsController : ControllerBase } /// Get agent-specific KPIs for the dashboard. - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)] [HttpGet("agent-stats")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] diff --git a/src/Heimdall.Web/Controllers/UsersController.cs b/src/Heimdall.Web/Controllers/UsersController.cs index 7ccee71..f5f24f0 100644 --- a/src/Heimdall.Web/Controllers/UsersController.cs +++ b/src/Heimdall.Web/Controllers/UsersController.cs @@ -21,7 +21,7 @@ namespace Heimdall.Api.Controllers; [ApiController] [Route("api/users")] -[Authorize(AuthenticationSchemes = "JwtBearer")] +[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [EnableRateLimiting("Api")] public class UsersController : ControllerBase { @@ -31,7 +31,7 @@ public class UsersController : ControllerBase /// List all users (Admin only). [HttpGet] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(typeof(PagedResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] public async Task List( @@ -45,7 +45,7 @@ public class UsersController : ControllerBase /// Get the current user's profile. [HttpGet("me")] - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] public async Task GetMyProfile(CancellationToken ct) @@ -62,7 +62,7 @@ public class UsersController : ControllerBase /// Update the current user's own profile. [HttpPut("me")] - [Authorize(AuthenticationSchemes = "JwtBearer")] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies")] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] @@ -82,7 +82,7 @@ public class UsersController : ControllerBase /// Get a user by ID (Admin only). [HttpGet("{id:guid}")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] public async Task GetById(Guid id, CancellationToken ct) @@ -95,7 +95,7 @@ public class UsersController : ControllerBase /// Create a new user (Admin only). [HttpPost] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task Create([FromBody] CreateUserRequest request, CancellationToken ct) @@ -109,7 +109,7 @@ public class UsersController : ControllerBase /// Update a user (Admin only). [HttpPut("{id:guid}")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -125,7 +125,7 @@ public class UsersController : ControllerBase /// Assign roles to a user (Admin only). [HttpPut("{id:guid}/roles")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task AssignRoles( @@ -139,7 +139,7 @@ public class UsersController : ControllerBase /// Assign sites to a user (Admin only). [HttpPut("{id:guid}/sites")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task AssignSites( @@ -153,7 +153,7 @@ public class UsersController : ControllerBase /// Reset a user's password (Admin only). [HttpPost("{id:guid}/reset-password")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(typeof(ResetPasswordResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task ResetPassword(Guid id, CancellationToken ct) @@ -167,7 +167,7 @@ public class UsersController : ControllerBase /// Delete a user account (Admin only). Self-deletion is forbidden. /// Cannot delete the last administrator. [HttpDelete("{id:guid}")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)] @@ -185,7 +185,7 @@ public class UsersController : ControllerBase /// Lock a user account (Admin only). [HttpPost("{id:guid}/lock")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task Lock(Guid id, CancellationToken ct) @@ -198,7 +198,7 @@ public class UsersController : ControllerBase /// Unlock a user account (Admin only). [HttpPost("{id:guid}/unlock")] - [Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.AdminUsers)] + [Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminUsers)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)] public async Task Unlock(Guid id, CancellationToken ct) diff --git a/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs b/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs index fa01758..66abe61 100644 --- a/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs +++ b/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs @@ -142,6 +142,23 @@ public class SameOriginHttpMessageHandler : DelegatingHandler } } + // Au premier rendu (SSR / F5), AuthState n'a pas de JWT (peuplé depuis le + // cookie) et le HttpClient serveur n'envoie pas le cookie du navigateur. + // On propage le cookie d'authentification du HttpContext courant pour que + // les appels API internes soient authentifiés pendant le rendu initial. + // Une fois le circuit actif, AuthState.AccessToken est présent et le + // Bearer (posé par HeimdallApiClient) prend le relais. + var http = _httpContextAccessor.HttpContext; + if (http is not null + && http.User?.Identity?.IsAuthenticated == true + && request.Headers.Authorization is null + && !request.Headers.Contains("Cookie")) + { + var cookie = http.Request.Headers.Cookie.ToString(); + if (!string.IsNullOrWhiteSpace(cookie)) + request.Headers.TryAddWithoutValidation("Cookie", cookie); + } + return base.SendAsync(request, cancellationToken); } }