Skip to content

Commit

Permalink
Fix stuffz
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Feb 3, 2025
1 parent 4500ebc commit 004b704
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion API/Controller/Devices/DeviceOtaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed partial class DevicesController
/// <response code="404">Could not find device or you do not have access to it</response>
[HttpGet("{deviceId}/ota")]
[MapToApiVersion("1")]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType<BaseResponse<IReadOnlyCollection<OtaItem>>>(StatusCodes.Status200OK, MediaTypeNames.Application.Json)]
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // DeviceNotFound
public async Task<IActionResult> GetOtaUpdateHistory([FromRoute] Guid deviceId, [FromServices] IOtaService otaService)
Expand Down
10 changes: 5 additions & 5 deletions API/Controller/Tokens/TokenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed partial class TokensController
/// </summary>
/// <response code="200">All tokens for the current user</response>
[HttpGet]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType<IEnumerable<TokenResponse>>(StatusCodes.Status200OK, MediaTypeNames.Application.Json)]
public async Task<IEnumerable<TokenResponse>> ListTokens()
{
Expand All @@ -52,7 +52,7 @@ public async Task<IEnumerable<TokenResponse>> ListTokens()
/// <response code="200">The token</response>
/// <response code="404">The token does not exist or you do not have access to it.</response>
[HttpGet("{tokenId}")]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType<TokenResponse>(StatusCodes.Status200OK, MediaTypeNames.Application.Json)]
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // ApiTokenNotFound
public async Task<IActionResult> GetTokenById([FromRoute] Guid tokenId)
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<IActionResult> GetTokenById([FromRoute] Guid tokenId)
/// <response code="200">Successfully deleted token</response>
/// <response code="404">The token does not exist or you do not have access to it.</response>
[HttpDelete("{tokenId}")]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // ApiTokenNotFound
public async Task<IActionResult> DeleteToken([FromRoute] Guid tokenId)
Expand All @@ -105,7 +105,7 @@ public async Task<IActionResult> DeleteToken([FromRoute] Guid tokenId)
/// <param name="body"></param>
/// <response code="200">The created token</response>
[HttpPost]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType<TokenCreatedResponse>(StatusCodes.Status200OK, MediaTypeNames.Application.Json)]
public async Task<TokenCreatedResponse> CreateToken([FromBody] CreateTokenRequest body)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<TokenCreatedResponse> CreateToken([FromBody] CreateTokenReques
/// <response code="200">The edited token</response>
/// <response code="404">The token does not exist or you do not have access to it.</response>
[HttpPatch("{tokenId}")]
[Authorize(Roles = "User")]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.UserSessionCookie)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // ApiTokenNotFound
public async Task<IActionResult> EditToken([FromRoute] Guid tokenId, [FromBody] EditTokenRequest body)
Expand Down
2 changes: 1 addition & 1 deletion API/Controller/Tokens/TokenSelfController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed partial class TokensController
/// <returns></returns>
/// <exception cref="Exception"></exception>
[HttpGet("self")]
[Authorize(Policy = OpenShockAuthPolicies.TokenSessionOnly)]
[Authorize(AuthenticationSchemes = OpenShockAuthSchemas.ApiToken)]
[ProducesResponseType<TokenResponse>(StatusCodes.Status200OK, MediaTypeNames.Application.Json)]
public TokenResponse GetSelfToken([FromServices] IUserReferenceService userReferenceService)
{
Expand Down
2 changes: 1 addition & 1 deletion Common/Authentication/OpenShockAuthPolicies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public static class OpenShockAuthPolicies
{
public const string TokenSessionOnly = "ApiTokenOnly";
public const string AdminOnly = "AdminOnly";
}
2 changes: 1 addition & 1 deletion Common/OpenShockServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ServicesResult AddOpenShockServices(this IServiceCollection servic

services.AddAuthorization(options =>
{
options.AddPolicy(OpenShockAuthPolicies.TokenSessionOnly, policy => policy.RequireClaim(ClaimTypes.AuthenticationMethod, OpenShockAuthSchemas.ApiToken));
options.AddPolicy(OpenShockAuthPolicies.AdminOnly, policy => policy.RequireRole("Admin", "System"));
// TODO: Add token permission policies
});

Expand Down

0 comments on commit 004b704

Please sign in to comment.