I have a question about RESTful API and security in a multi-tenant environment.
Imagine you have an endpoint: api/branches/:branchId/accounts/:accountId
Authentication is through bearer tokens (oauth2) . Each token includes a set of statements related to the caller. branchId included in the token, and each user belongs to one branch.
Security restrictions are as follows:
- The branchId of the GET request must match the identifier stored in the token request.
- accountId must be a valid account inside the branch identified by
branchId .
The question is which of the following solutions is correct?
- Maintain the endpoint:
api/branches/:branchId/accounts/:accountId . And do the necessary security checks. - Change the endpoint to:
api/accounts/:accountId , get the BranchId value from the token, and then perform the remaining security checks.
The application must be multi-tenant. Each branch is a tenant, and each user can only access information related to its separate branch. Thanks!
source share