# HG changeset patch # User Matthew Wild # Date 1582739873 0 # Node ID 8ac5d9933106d270a6879b0eefc8a21cbf8f2733 # Parent d5ecb9b9cb3b9c67227fadb7733faeb0a827506e mod_http_oauth2: Implement real tokens using mod_authtokens diff -r d5ecb9b9cb3b -r 8ac5d9933106 mod_http_oauth2/mod_http_oauth2.lua --- 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