Skip to content

Instantly share code, notes, and snippets.

@vdel26
Last active November 13, 2022 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vdel26/9050170 to your computer and use it in GitHub Desktop.
Save vdel26/9050170 to your computer and use it in GitHub Desktop.
Extracting Basic Auth token
--[[
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