Skip to content

Commit

Permalink
feat: use custome auth header name
Browse files Browse the repository at this point in the history
  • Loading branch information
Amirhossein Rajabi committed Oct 8, 2024
1 parent 561e8e8 commit ba40e02
Showing 1 changed file with 5 additions and 12 deletions.
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

0 comments on commit ba40e02

Please sign in to comment.