Skip to content

Commit 32206d9

Browse files
authored
Update nginx-jwt.lua
1 parent 4c9e58d commit 32206d9

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

nginx-jwt.lua

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,40 @@ function M.auth(claim_specs)
2626
-- require Authorization request header
2727
local auth_header = ngx.var.http_Authorization
2828

29-
if auth_header == nil then
30-
ngx.log(ngx.WARN, "No Authorization header")
31-
ngx.exit(ngx.HTTP_UNAUTHORIZED)
29+
token_site = os.getenv("NGINX_JWT_TOKEN_SITE")
30+
31+
if token_site == nil then
32+
ngx.log(ngx.WARN, "No token site found, use default: HEADER")
33+
token_site = "HEADER"
3234
end
35+
36+
if token_site == "HEADER" then
37+
if auth_header == nil then
38+
ngx.log(ngx.WARN, "No Authorization header")
39+
ngx.exit(ngx.HTTP_UNAUTHORIZED)
40+
end
3341

34-
ngx.log(ngx.INFO, "Authorization: " .. auth_header)
42+
ngx.log(ngx.INFO, "Authorization: " .. auth_header)
3543

3644
-- require Bearer token
37-
local _, _, token = string.find(auth_header, "Bearer%s+(.+)")
45+
local _, _, token = string.find(auth_header, "Bearer%s+(.+)")
3846

39-
if token == nil then
40-
ngx.log(ngx.WARN, "Missing token")
41-
ngx.exit(ngx.HTTP_UNAUTHORIZED)
4247
end
43-
48+
49+
if token_site == "COOKIE" then
50+
token = ngx.var.cookie_bearer
51+
end
52+
53+
if token_site == "REQUEST" then
54+
token = ngx.var.arg_bearer
55+
end
56+
57+
if token == nil then
58+
ngx.log(ngx.WARN, "Missing token")
59+
ngx.exit(ngx.HTTP_UNAUTHORIZED)
60+
end
61+
62+
4463
ngx.log(ngx.INFO, "Token: " .. token)
4564

4665
-- require valid JWT

0 commit comments

Comments
 (0)