-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Description
The current implementation of the JWT middleware applies the same authorization logic to all route functions under a specific route prefix. This approach lacks the flexibility required in production environments where different API endpoints often need different authorization checks.
Current Behavior
The registered Authorizator is called before the execution of any route function that uses the JWT middleware. This results in uniform authorization logic across all functions under the same route prefix.
Desired Behavior
Implement a mechanism to apply different authorization logic to different HTTP handlers, allowing for more granular and specific access control. For example:
- For an endpoint that operates on a document, check if the current user has permission to edit that specific document.
- For an endpoint that updates a group name, verify if the current user has the appropriate group admin role.
The method I can think of is to construct multiple JWT middleware objects, one for each authorization logic. These JWT objects would have the same Authenticator, PayloadFunc, and IdentityHandler, with only the Authorizator being different. Then, use the corresponding JWT middleware object for specific route functions. I think this approach looks a bit messy. Is there a more elegant way to implement this requirement?