Changeset

3908:8ac5d9933106

mod_http_oauth2: Implement real tokens using mod_authtokens
author Matthew Wild <mwild1@gmail.com>
date Wed, 26 Feb 2020 17:57:53 +0000
parents 3907:d5ecb9b9cb3b
children 3909:eb27e51cf2c9
files mod_http_oauth2/mod_http_oauth2.lua
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_oauth2/mod_http_oauth2.lua	Tue Feb 25 23:33:55 2020 +0100
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Wed Feb 26 17:57:53 2020 +0000
@@ -1,11 +1,11 @@
-module:set_global();
-
 local http = require "util.http";
 local jid = require "util.jid";
 local json = require "util.json";
 local usermanager = require "core.usermanager";
 local errors = require "util.error";
 
+local tokens = module:depends("authtokens");
+
 local function oauth_error(err_name, err_desc)
 	return errors.new({
 		type = "modify";
@@ -17,9 +17,11 @@
 end
 
 local function new_access_token(username, host, scope, ttl)
+	local token_jid = jid.join(username, host);
+	local token = tokens.create_jid_token(token_jid, token_jid, scope, ttl);
 	return {
 		token_type = "bearer";
-		access_token = "test-token";
+		access_token = token;
 		expires_in = ttl;
 		-- TODO: include refresh_token when implemented
 	};
@@ -34,7 +36,7 @@
 	if params.scope then
 		return oauth_error("invalid_scope", "unknown scope requested");
 	end
-	if not (request_username and request_host) or not (hosts[request_host]) then
+	if not (request_username and request_host) or request_host ~= module.host then
 		return oauth_error("invalid_request", "invalid JID");
 	end
 	if usermanager.test_password(request_username, request_host, request_password) then