Last active
November 13, 2022 18:22
-
-
Save vdel26/9050170 to your computer and use it in GitHub Desktop.
Extracting Basic Auth token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Authorization logic | |
]]-- | |
function get_auth_params(where, method) | |
local params = {} | |
if where == "headers" then | |
params = ngx.req.get_headers() | |
elseif where == "basicauth" then | |
params = ngx.req.get_headers() | |
if params["Authorization"] then | |
local m = ngx.re.match(params["Authorization"], "Basic\\s(.+)") | |
if m then | |
params.user_key = m[1] | |
end | |
end | |
elseif method == "GET" then | |
params = ngx.req.get_uri_args() | |
else | |
ngx.req.read_body() | |
params = ngx.req.get_post_args() | |
end | |
return first_values(params) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment