Comparison

mod_http_oauth2/mod_http_oauth2.lua @ 5427:d69c10327d6d

mod_http_oauth2: More functional functions
author Kim Alvefur <zash@zash.se>
date Sun, 07 May 2023 19:11:20 +0200
parent 5426:f75d95f27da7
child 5428:07e166b34c4c
comparison
equal deleted inserted replaced
5426:f75d95f27da7 5427:d69c10327d6d
114 114
115 local function can_assume_role(username, requested_role) 115 local function can_assume_role(username, requested_role)
116 return usermanager.user_can_assume_role(username, module.host, requested_role); 116 return usermanager.user_can_assume_role(username, module.host, requested_role);
117 end 117 end
118 118
119 local function role_assumable_by(username)
120 return function(role)
121 return can_assume_role(username, role);
122 end
123 end
124
119 local function user_assumable_roles(username, requested_roles) 125 local function user_assumable_roles(username, requested_roles)
120 return array.filter(requested_roles, function(role) 126 return array.filter(requested_roles, role_assumable_by(username));
121 return can_assume_role(username, role);
122 end);
123 end 127 end
124 128
125 local function select_role(username, requested_roles) 129 local function select_role(username, requested_roles)
126 if requested_roles then 130 if requested_roles then
127 for _, requested_role in ipairs(requested_roles) do 131 for _, requested_role in ipairs(requested_roles) do