pavlenkodev commented on issue #10730:
URL: https://github.com/apache/apisix/issues/10730#issuecomment-1871786129
> Hi @Vacant2333 The returned functions are as follows.Its main purpose is
to extract the "sub" claim from a JWT found in the "Authorization" header of an
HTTP request. If the header is missing or the JWT is not present, it returns
the default value "not found."
>
> ```
> return function()
> local core = require("apisix.core")
>
> core.ctx.register_var("sub", function(ctx)
> local core = require("apisix.core")
> local jwt = require("resty.jwt")
> local sub_not_found = "not found"
>
> local access_token = core.request.header(ctx, "Authorization")
> local result_value
>
> if not access_token then
> result_value = sub_not_found
> return result_value
> end
>
> local jwt_obj = jwt:load_jwt(access_token)
> result_value = tostring(jwt_obj.payload.sub)
>
> return result_value
> end)
> end
> ```
Due to the different time zones, I couldn't answer right away. Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]