From ba40e020f80f39707ec8d2b5c69111719f3429a6 Mon Sep 17 00:00:00 2001 From: Amirhossein Rajabi Date: Tue, 8 Oct 2024 15:53:55 +0330 Subject: [PATCH] feat: use custome auth header name --- apisix/plugins/openid-connect.lua | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/apisix/plugins/openid-connect.lua b/apisix/plugins/openid-connect.lua index c4388abbfc6c..d88ce9944a82 100644 --- a/apisix/plugins/openid-connect.lua +++ b/apisix/plugins/openid-connect.lua @@ -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", @@ -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. @@ -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