This repository was archived by the owner on Jan 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ sudo cp haproxy-cloudflare-jwt-validator/src/* /usr/local/share/lua/5.3
2525
2626# Version
2727
28- 0.1 .0
28+ 0.2 .0
2929
3030# Usage
3131
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ backend http-backend
3535 http-request set-var(txn.audience) str("1234567890abcde1234567890abcde1234567890abcde")
3636 http-request lua.jwtverify
3737 http-request deny unless { var(txn.authorized) -m bool }
38+ http-request set-header custom-groups %[var(txn.http___schemas_groups)]
3839 server debug_http_listener debug_http_listener:80 check
3940
4041backend cloudflare_jwt
Original file line number Diff line number Diff line change @@ -30,7 +30,14 @@ CLAIM='{
3030 "exp": 3993204858,
3131 "type": "app",
3232 "identity_nonce": "11111111111",
33- "custom": {}
33+ "custom": {
34+ "http://schemas/groups": [
35+ "application_admin",
36+ "application_group1",
37+ "application_group2",
38+ "application_group3"
39+ ]
40+ }
3441}'
3542
3643while ! nc -z localhost 8080; do
Original file line number Diff line number Diff line change @@ -278,6 +278,20 @@ function jwtverify(txn)
278278 goto out
279279 end
280280
281+ -- 7. Add custom values from payload to variable
282+ if token .payloaddecoded .custom ~= nil then
283+ for name , payload in pairs (token .payloaddecoded .custom ) do
284+ local clean_name = name :gsub (" %W" ," _" )
285+ local clean_value = payload
286+ if (type (payload ) == ' table' ) then
287+ clean_value = table.concat (payload , ' ,' )
288+ end
289+
290+ txn .set_var (txn , " txn." .. clean_name , clean_value )
291+ log_debug (" txn." .. clean_name .. " is defined from payload" )
292+ end
293+ end
294+
281295 -- 8. Set authorized variable
282296 log_debug (" req.authorized = true" )
283297 txn .set_var (txn , " txn.authorized" , true )
You can’t perform that action at this time.
0 commit comments