diff --git a/examples/OpenResty/lua/group_auth.lua b/examples/OpenResty/lua/group_auth.lua index 83e7c619..a86da9a9 100644 --- a/examples/OpenResty/lua/group_auth.lua +++ b/examples/OpenResty/lua/group_auth.lua @@ -2,6 +2,16 @@ -- Group Authentication -- via X-Vouch-IdP-Groups -- ============================== +-- Function to turn a table with only values into a k=>v table +function Set (list) + local set = {} + for _, l in ipairs(list) do set[l] = true end + return set +end +-- Function to find a key in a table +function tableHasKey(table,key) + return table[key] ~= nil +end -- Validate that a user is in a group local authorized_groups = Set { "CN=Domain Users,CN=Users,DC=Contoso,DC=com", @@ -29,4 +39,4 @@ if ngx.var.auth_resp_x_vouch_idp_claims_groups then else -- Throw forbidden if variable doesn't exist ngx.exit(ngx.HTTP_FORBIDDEN) -end \ No newline at end of file +end diff --git a/examples/OpenResty/lua/user_auth.lua b/examples/OpenResty/lua/user_auth.lua index 91f6c62a..e979cbcc 100644 --- a/examples/OpenResty/lua/user_auth.lua +++ b/examples/OpenResty/lua/user_auth.lua @@ -2,6 +2,16 @@ -- User Authentication -- via X-Vouch-User -- ============================== +-- Function to turn a table with only values into a k=>v table +function Set (list) + local set = {} + for _, l in ipairs(list) do set[l] = true end + return set +end +-- Function to find a key in a table +function tableHasKey(table,key) + return table[key] ~= nil +end -- Validate a user in nginx, instead of vouch local authorized_users = Set { "my@account.com", @@ -17,4 +27,4 @@ if ngx.var.auth_resp_x_vouch_user then else -- Throw forbidden if variable doesn't exist ngx.exit(ngx.HTTP_FORBIDDEN) -end \ No newline at end of file +end