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

set ngx.ctx.authenticated_groups if groups claim is present #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ ngx.ctx.authenticated_consumer = {
}
```

The plugin will try to retrieve the user's groups from a field in the token (default `groups`)
and set `ngx.ctx.authenticated_groups` so that Kong authorization plugins can make decisions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and set `ngx.ctx.authenticated_groups` so that Kong authorization plugins can make decisions
and set `kong.ctx.shared.authenticated_groups` so that Kong authorization plugins can make decisions

based on the user's group membership.


## Dependencies

Expand Down Expand Up @@ -82,6 +86,7 @@ You also need to set the `KONG_PLUGINS` environment variable
| `config.bearer_only` | no | false | Only introspect tokens without redirecting |
| `config.realm` | kong | false | Realm used in WWW-Authenticate response header |
| `config.logout_path` | /logout | false | Absolute path used to logout from the OIDC RP |
| `config.groups_claim` | groups | false | Name of the claim in the token to get groups from |

### Enabling

Expand Down
1 change: 1 addition & 0 deletions kong/plugins/oidc/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function handle(oidcConfig)
if response then
if (response.user) then
utils.injectUser(response.user)
utils.injectGroups(response.user, oidcConfig.groups_claim)
end
if (response.access_token) then
utils.injectAccessToken(response.access_token)
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/oidc/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ return {
recovery_page_path = { type = "string" },
logout_path = { type = "string", required = false, default = '/logout' },
redirect_after_logout_uri = { type = "string", required = false, default = '/' },
filters = { type = "string" }
filters = { type = "string" },
groups_claim = { type = "string", required = false, default = "groups" }
}
}
7 changes: 7 additions & 0 deletions kong/plugins/oidc/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function M.get_options(config, ngx)
filters = parseFilters(config.filters),
logout_path = config.logout_path,
redirect_after_logout_uri = config.redirect_after_logout_uri,
groups_claim = config.groups_claim,
}
end

Expand Down Expand Up @@ -85,6 +86,12 @@ function M.injectUser(user)
ngx.req.set_header("X-Userinfo", ngx.encode_base64(userinfo))
end

function M.injectGroups(user, claim)
if user[claim] ~= nil then
ngx.ctx.authenticated_groups = user[claim]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ngx.ctx.authenticated_groups = user[claim]
kong.ctx.shared.authenticated_groups = user[claim]

end
end

function M.has_bearer_access_token()
local header = ngx.req.get_headers()['Authorization']
if header and header:find(" ") then
Expand Down