Skip to content

Advice on how to handle multiple roles in JWT #3698

Closed Answered by wolfgangwalther
mkleczek asked this question in Q&A
Discussion options

You must be logged in to vote

Those were exactly the ideas that I had in mind, too:

Another idea is to have a dedicated database role per each subset of possible user roles - but that is unfeasible for larger number of user roles. And there is also a question how to map the list provided in the JWT claim to such a database role.

Algorithm:

  • Keep all those roles in a table with a smallint pk
  • map the roles in the JWT to a bitfield, where each role corresponds to the pk-th bit.
  • turn the bitfield into an int and create database roles for each of those combinations, so for example claimXXX.
  • do this in a pre-request function, read the JWT, switch to the resulting role here.

Another idea would be to have a reverse proxy …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mkleczek
Comment options

@wolfgangwalther
Comment options

Answer selected by mkleczek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants