Comparison

mod_adhoc_oauth2_client/mod_adhoc_oauth2_client.lua @ 4268:871d140d61bb

mod_adhoc_oauth2_client: Fix including final client_id in result form The client_id is composed of the details needed for retrieving the data, making it redundant to include in the data, albeit somewhat convenient sometimes. Decided to remove it anyways, but forgot to change the result.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Nov 2020 17:00:26 +0100
parent 4267:43284437c5ed
child 5260:a9c1cc91d3d6
comparison
equal deleted inserted replaced
4267:43284437c5ed 4268:871d140d61bb
41 for field, err in pairs(formerr) do table.insert(errmsg, field .. ": " .. err); end 41 for field, err in pairs(formerr) do table.insert(errmsg, field .. ": " .. err); end
42 return {status = "error"; error = {message = table.concat(errmsg, "\n")}}; 42 return {status = "error"; error = {message = table.concat(errmsg, "\n")}};
43 end 43 end
44 44
45 local creator = jid.split(data.from); 45 local creator = jid.split(data.from);
46 local client_id = id.short(); 46 local client_uid = id.short();
47 local client_id = jid.join(creator, module.host, client_uid);
47 local client_secret = id.long(); 48 local client_secret = id.long();
48 local salt = id.medium(); 49 local salt = id.medium();
49 local i = iteration_count; 50 local i = iteration_count;
50 51
51 client.secret_hash = base64.encode(hashes.pbkdf2_hmac_sha256(client_secret, salt .. pepper, i)); 52 client.secret_hash = base64.encode(hashes.pbkdf2_hmac_sha256(client_secret, salt .. pepper, i));
52 client.iteration_count = i; 53 client.iteration_count = i;
53 client.salt = salt; 54 client.salt = salt;
54 55
55 local ok, err = errors.coerce(clients:set(creator, client_id, client)); 56 local ok, err = errors.coerce(clients:set(creator, client_uid, client));
56 module:log("info", "OAuth2 client %q created by %s", client_id, data.from); 57 module:log("info", "OAuth2 client %q created by %s", client_id, data.from);
57 if not ok then return {status = "canceled"; error = {message = err}}; end 58 if not ok then return {status = "canceled"; error = {message = err}}; end
58 59
59 return {status = "completed"; result = {layout = client_created; values = {client_id = client.client_id; client_secret = client_secret}}}; 60 return {status = "completed"; result = {layout = client_created; values = {client_id = client_id; client_secret = client_secret}}};
60 end 61 end
61 62
62 local handler = adhoc.new_simple_form(new_client, create_client); 63 local handler = adhoc.new_simple_form(new_client, create_client);
63 64
64 module:provides("adhoc", module:require "adhoc".new(new_client.title, new_client[1].value, handler, "local_user")); 65 module:provides("adhoc", module:require "adhoc".new(new_client.title, new_client[1].value, handler, "local_user"));