Skip to content

Issue: Achieve different authorization in different HTTP HandlerFunc #20

@JiSuanSiWeiShiXun

Description

@JiSuanSiWeiShiXun

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions