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

feat: use custom auth header name #11628

Open
wants to merge 2 commits 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
17 changes: 5 additions & 12 deletions apisix/plugins/openid-connect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ local schema = {
pattern = "^[^:]+$"
}
},
auth_accept_token_as_header_name = { type = "string", default = "Authorization" },
required_scopes = {
description = "List of scopes that are required to be granted to the access token",
type = "array",
Expand Down Expand Up @@ -319,19 +320,11 @@ function _M.check_schema(conf)
end


local function get_bearer_access_token(ctx)
local function get_bearer_access_token(ctx, conf)
-- Get Authorization header, maybe.
local auth_header = core.request.header(ctx, "Authorization")
local auth_header = core.request.header(ctx, conf.auth_accept_token_as_header_name)
if not auth_header then
-- No Authorization header, get X-Access-Token header, maybe.
local access_token_header = core.request.header(ctx, "X-Access-Token")
if not access_token_header then
-- No X-Access-Token header neither.
return false, nil, nil
end

-- Return extracted header value.
return true, access_token_header, nil
return false, nil, nil
end

-- Check format of Authorization header.
Expand All @@ -356,7 +349,7 @@ end

local function introspect(ctx, conf)
-- Extract token, maybe.
local has_token, token, err = get_bearer_access_token(ctx)
local has_token, token, err = get_bearer_access_token(ctx, conf)

if err then
return ngx.HTTP_BAD_REQUEST, err, nil, nil
Expand Down
1 change: 1 addition & 0 deletions docs/en/latest/plugins/openid-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ description: OpenID Connect allows the client to obtain user information from th
| introspection_interval | integer | False | 0 | | TTL of the cached and introspected access token in seconds. |
| introspection_expiry_claim | string | False | | | Name of the expiry claim, which controls the TTL of the cached and introspected access token. The default value is 0, which means this option is not used and the plugin defaults to use the TTL passed by expiry claim defined in `introspection_expiry_claim`. If `introspection_interval` is larger than 0 and less than the TTL passed by expiry claim defined in `introspection_expiry_claim`, use `introspection_interval`. |
| introspection_addon_headers | string[] | False | | | Array of strings. Used to append additional header values to the introspection HTTP request. If the specified header does not exist in origin request, value will not be appended. |
| auth_accept_token_as_header_name | string | False | "Authorization" | | Name of the request header from which to accept the access token. Defaults to `Authorization`. |

NOTE: `encrypt_fields = {"client_secret"}` is also defined in the schema, which means that the field will be stored encrypted in etcd. See [encrypted storage fields](../plugin-develop.md#encrypted-storage-fields).

Expand Down