Skip to content

Commit d3a5a5e

Browse files
author
jarvis
committed
fix: Add missing authorization to Identity endpoints
- ChangePasswordEndpoint: Add RequireAuthorization() for logged-in users - GetUserProfileEndpoint: Add RequireAuthorization() for logged-in users - AssignUserRolesEndpoint: Add RequirePermission(Users.ManageRoles) - GetUserPermissionsEndpoint: Add RequirePermission(Users.View) - Add Users.ManageRoles permission constant These endpoints were previously accessible without proper authorization checks.
1 parent 18d44ce commit d3a5a5e

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/BuildingBlocks/Shared/Identity/IdentityPermissionConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static class Users
88
public const string Create = "Permissions.Users.Create";
99
public const string Update = "Permissions.Users.Update";
1010
public const string Delete = "Permissions.Users.Delete";
11+
public const string ManageRoles = "Permissions.Users.ManageRoles";
1112
}
1213

1314
public static class Roles

src/Modules/Identity/Modules.Identity/Features/v1/Users/AssignUserRoles/AssignUserRolesEndpoint.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using FSH.Modules.Identity.Contracts.v1.Users.AssignUserRoles;
1+
using FSH.Framework.Shared.Identity;
2+
using FSH.Framework.Shared.Identity.Authorization;
3+
using FSH.Modules.Identity.Contracts.v1.Users.AssignUserRoles;
24
using Mediator;
35
using Microsoft.AspNetCore.Builder;
46
using Microsoft.AspNetCore.Http;
@@ -27,6 +29,7 @@ internal static RouteHandlerBuilder MapAssignUserRolesEndpoint(this IEndpointRou
2729
})
2830
.WithName("AssignUserRoles")
2931
.WithSummary("Assign roles to user")
30-
.WithDescription("Assign one or more roles to a user.");
32+
.WithDescription("Assign one or more roles to a user.")
33+
.RequirePermission(IdentityPermissionConstants.Users.ManageRoles);
3134
}
3235
}

src/Modules/Identity/Modules.Identity/Features/v1/Users/ChangePassword/ChangePasswordEndpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal static RouteHandlerBuilder MapChangePasswordEndpoint(this IEndpointRout
2121
})
2222
.WithName("ChangePassword")
2323
.WithSummary("Change password")
24-
.WithDescription("Change the current user's password.");
24+
.WithDescription("Change the current user's password.")
25+
.RequireAuthorization();
2526
}
2627
}

src/Modules/Identity/Modules.Identity/Features/v1/Users/GetUserPermissions/GetUserPermissionsEndpoint.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Security.Claims;
22
using FSH.Framework.Core.Exceptions;
3+
using FSH.Framework.Shared.Identity;
4+
using FSH.Framework.Shared.Identity.Authorization;
35
using FSH.Framework.Shared.Identity.Claims;
46
using FSH.Modules.Identity.Contracts.v1.Users.GetUserPermissions;
57
using Mediator;
@@ -24,6 +26,7 @@ internal static RouteHandlerBuilder MapGetCurrentUserPermissionsEndpoint(this IE
2426
})
2527
.WithName("GetCurrentUserPermissions")
2628
.WithSummary("Get current user permissions")
27-
.WithDescription("Retrieve permissions for the authenticated user.");
29+
.WithDescription("Retrieve permissions for the authenticated user.")
30+
.RequirePermission(IdentityPermissionConstants.Users.View);
2831
}
2932
}

src/Modules/Identity/Modules.Identity/Features/v1/Users/GetUserProfile/GetUserProfileEndpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal static RouteHandlerBuilder MapGetMeEndpoint(this IEndpointRouteBuilder
2424
})
2525
.WithName("GetCurrentUserProfile")
2626
.WithSummary("Get current user profile")
27-
.WithDescription("Retrieve the authenticated user's profile from the access token.");
27+
.WithDescription("Retrieve the authenticated user's profile from the access token.")
28+
.RequireAuthorization();
2829
}
2930
}

0 commit comments

Comments
 (0)