changeset 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 3e19c25ff93e
children 8ed261a08a9c
files mod_http_oauth2/mod_http_oauth2.lua
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_oauth2/mod_http_oauth2.lua	Thu Feb 27 00:59:17 2020 +0100
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Thu Feb 27 22:58:56 2020 +0100
@@ -16,8 +16,7 @@
 	});
 end
 
-local function new_access_token(username, host, scope, ttl)
-	local token_jid = jid.join(username, host);
+local function new_access_token(token_jid, scope, ttl)
 	local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl);
 	return {
 		token_type = "bearer";
@@ -40,7 +39,8 @@
 		return oauth_error("invalid_request", "invalid JID");
 	end
 	if usermanager.test_password(request_username, request_host, request_password) then
-		return json.encode(new_access_token(request_username, request_host, nil, nil));
+		local granted_jid = jid.join(request_username, request_host);
+		return json.encode(new_access_token(granted_jid, request_host, nil, nil));
 	end
 	return oauth_error("invalid_grant", "incorrect credentials");
 end