comparison mod_http_oauth2/mod_http_oauth2.lua @ 3918:dea6bea2ddd3

mod_http_oauth2: Refactor re-joining of JID out of token constructor Preparing for resource-bound tokens and handling of Components
author Kim Alvefur <zash@zash.se>
date Thu, 27 Feb 2020 22:58:56 +0100
parents 80dffbbd056b
children 8ed261a08a9c
comparison
equal deleted inserted replaced
3917:3e19c25ff93e 3918:dea6bea2ddd3
14 text = err_desc and (err_name..": "..err_desc) or err_name; 14 text = err_desc and (err_name..": "..err_desc) or err_name;
15 context = { oauth2_response = { error = err_name, error_description = err_desc } }; 15 context = { oauth2_response = { error = err_name, error_description = err_desc } };
16 }); 16 });
17 end 17 end
18 18
19 local function new_access_token(username, host, scope, ttl) 19 local function new_access_token(token_jid, scope, ttl)
20 local token_jid = jid.join(username, host);
21 local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl); 20 local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl);
22 return { 21 return {
23 token_type = "bearer"; 22 token_type = "bearer";
24 access_token = token; 23 access_token = token;
25 expires_in = ttl; 24 expires_in = ttl;
38 end 37 end
39 if not (request_username and request_host) or request_host ~= module.host then 38 if not (request_username and request_host) or request_host ~= module.host then
40 return oauth_error("invalid_request", "invalid JID"); 39 return oauth_error("invalid_request", "invalid JID");
41 end 40 end
42 if usermanager.test_password(request_username, request_host, request_password) then 41 if usermanager.test_password(request_username, request_host, request_password) then
43 return json.encode(new_access_token(request_username, request_host, nil, nil)); 42 local granted_jid = jid.join(request_username, request_host);
43 return json.encode(new_access_token(granted_jid, request_host, nil, nil));
44 end 44 end
45 return oauth_error("invalid_grant", "incorrect credentials"); 45 return oauth_error("invalid_grant", "incorrect credentials");
46 end 46 end
47 47
48 function handle_token_grant(event) 48 function handle_token_grant(event)