Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for configuration of the JWT field from which secret key is drawn #837

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions kong/plugins/jwt/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function _M.execute(conf)

local claims = jwt.claims

local jwt_secret_key = claims.iss
local jwt_secret_key = claims[conf.secret_key_field]
if not jwt_secret_key then
ngx.ctx.stop_phases = true
return responses.send_HTTP_UNAUTHORIZED("No mandatory 'iss' in claims")
return responses.send_HTTP_UNAUTHORIZED("No mandatory '"..conf.secret_key_field.."' in claims")
end

-- Retrieve the secret
Expand All @@ -83,7 +83,7 @@ function _M.execute(conf)

if not jwt_secret then
ngx.ctx.stop_phases = true
return responses.send_HTTP_FORBIDDEN("No credentials found for given 'iss'")
return responses.send_HTTP_FORBIDDEN("No credentials found for given '"..conf.secret_key_field.."'")
end

-- Now verify the JWT signature
Expand Down Expand Up @@ -111,7 +111,7 @@ function _M.execute(conf)
-- However this should not happen
if not consumer then
ngx.ctx.stop_phases = true
return responses.send_HTTP_FORBIDDEN(string_format("Could not find consumer for '%s=%s'", "iss", jwt_secret_key))
return responses.send_HTTP_FORBIDDEN(string_format("Could not find consumer for '%s=%s'", conf.secret_key_field, jwt_secret_key))
end

ngx.req.set_header(constants.HEADERS.CONSUMER_ID, consumer.id)
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/jwt/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ return {
no_consumer = true,
fields = {
uri_param_names = {type = "array", default = {"jwt"}},
secret_key_field = {type = "string", default = "iss"},
claims_to_verify = {type = "array", enum = {"exp", "nbf"}}
}
}