comparison mod_http_oauth2/mod_http_oauth2.lua @ 5185:09d6bbd6c8a4

mod_http_oauth2: Fix treatment of 'redirect_uri' parameter in code flow It's optional and the one stored in the client registration should really be used instead. RFC 6749 says an URI provided as parameter MUST be validated against the stored one but does not say how. Given that the client needs their secret to proceed, it seems fine to leave this for later.
author Kim Alvefur <zash@zash.se>
date Thu, 02 Mar 2023 22:00:42 +0100
parents 20ba6340f524
children fa3059e653fa
comparison
equal deleted inserted replaced
5184:313937349fbc 5185:09d6bbd6c8a4
92 return json.encode(new_access_token(granted_jid, granted_scopes, nil)); 92 return json.encode(new_access_token(granted_jid, granted_scopes, nil));
93 end 93 end
94 94
95 function response_type_handlers.code(params, granted_jid) 95 function response_type_handlers.code(params, granted_jid)
96 if not params.client_id then return oauth_error("invalid_request", "missing 'client_id'"); end 96 if not params.client_id then return oauth_error("invalid_request", "missing 'client_id'"); end
97 if not params.redirect_uri then return oauth_error("invalid_request", "missing 'redirect_uri'"); end
98 97
99 local client_owner, client_host, client_id = jid.prepped_split(params.client_id); 98 local client_owner, client_host, client_id = jid.prepped_split(params.client_id);
100 if client_host ~= module.host then 99 if client_host ~= module.host then
101 return oauth_error("invalid_client", "incorrect credentials"); 100 return oauth_error("invalid_client", "incorrect credentials");
102 end 101 end
116 }); 115 });
117 if not ok then 116 if not ok then
118 return {status_code = 429}; 117 return {status_code = 429};
119 end 118 end
120 119
121 local redirect = url.parse(params.redirect_uri); 120 local redirect = url.parse(params.redirect_uri or client.redirect_uri);
122 local query = http.formdecode(redirect.query or ""); 121 local query = http.formdecode(redirect.query or "");
123 if type(query) ~= "table" then query = {}; end 122 if type(query) ~= "table" then query = {}; end
124 table.insert(query, { name = "code", value = code }) 123 table.insert(query, { name = "code", value = code })
125 if params.state then 124 if params.state then
126 table.insert(query, { name = "state", value = params.state }); 125 table.insert(query, { name = "state", value = params.state });