You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to extend jwt-auth plugin to store the authenticated JWT in the request context, so that it can easily be used in a plugin which executes after (lower priority), such as a custom ACL based on JWT payload.
Benefits
These are the benefits that come to my mind:
hiding the token from headers - this allows to enable hide_credentials and hide the JWT from the server receiving the request, but still allows subsequent plugins to access it;
less redundant code - the following plugins do not have to import extra modules to parse again the token, but can simply access its claims as a table.
Example
Suppose the jwt-auth plugin stores the decoded jwt object in request context (jwt-auth.lua):
function_M.rewrite(conf, ctx)
-- [...]ifnotctx.jwt_objthen-- Technically this can only happen when the JWT plugin didn't run for this request, or the priority was lowercore.log.warn("Token object not found in ctx.")
return401, {message="Missing JWT in request"}
endlocalauthorized=falselocalroles=ctx.jwt_obj.payload.roles-- Do something with rolesfori, valueinipairs(tab) doifvalue=="admin" thenauthorized=trueendendifnotauthorizedthencore.log.warn("Request not authorized")
return403, {message="You are not allowed to access this resource"}
end-- [...]end
Description
I'd like to extend jwt-auth plugin to store the authenticated JWT in the request context, so that it can easily be used in a plugin which executes after (lower priority), such as a custom ACL based on JWT payload.
Benefits
These are the benefits that come to my mind:
hide_credentials
and hide the JWT from the server receiving the request, but still allows subsequent plugins to access it;Example
Suppose the
jwt-auth
plugin stores the decoded jwt object in request context (jwt-auth.lua
):Custom plugin example (
my-acl.lua
):Additional Information
Kong JWT Plugin stores the encoded token in context, which I find interesting but a little bit unhandy: https://github.com/Kong/kong/blob/d4ab528fa2414d996861a43e58406c02b4978157/kong/plugins/jwt/handler.lua#L146
The text was updated successfully, but these errors were encountered: