Annotate

plugins/bind.lua @ 498:50d0bd035bb7

util.sasl.oauthbearer: Don't send authzid It's not needed and not recommended in XMPP unless we want to act as someone other than who we authenticate as. We find out the JID during resource binding.
author Kim Alvefur <zash@zash.se>
date Fri, 23 Jun 2023 12:09:49 +0200
parent 490:6b2f31da9610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 245
diff changeset
1 local verse = require "verse";
490
6b2f31da9610 Update for new Prosody module namespace
Kim Alvefur <zash@zash.se>
parents: 457
diff changeset
2 local jid = require "prosody.util.jid";
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 245
diff changeset
3
9
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local xmlns_bind = "urn:ietf:params:xml:ns:xmpp-bind";
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 function verse.plugins.bind(stream)
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local function handle_features(features)
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 if stream.bound then return; end
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 stream:debug("Binding resource...");
457
73d4eb93657b Update to use util.id for random ids instead of counters (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents: 300
diff changeset
10 stream:send_iq(verse.iq({ id="bind",type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource),
9
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function (reply)
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if reply.attr.type == "result" then
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local result_jid = reply
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 :get_child("bind", xmlns_bind)
245
19356e2150f3 plugins.bind: get_child_text()
Kim Alvefur <zash@zash.se>
parents: 197
diff changeset
15 :get_child_text("jid");
9
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 stream.username, stream.host, stream.resource = jid.split(result_jid);
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 stream.jid, stream.bound = result_jid, true;
160
5cbbfe42212e plugins.bind: Fix the bind-success event, now fires with data { jid = result_jid } (thanks Jon)
Matthew Wild <mwild1@gmail.com>
parents: 78
diff changeset
18 stream:event("bind-success", { jid = result_jid });
9
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 elseif reply.attr.type == "error" then
43
a33036b7e5ab verse.plugins.bind: Fix incorrect variable name causing traceback on unsuccessful bind
Matthew Wild <mwild1@gmail.com>
parents: 40
diff changeset
20 local err = reply:child_with_name("error");
a33036b7e5ab verse.plugins.bind: Fix incorrect variable name causing traceback on unsuccessful bind
Matthew Wild <mwild1@gmail.com>
parents: 40
diff changeset
21 local type, condition, text = reply:get_error();
78
f4188eff53a7 verse.client, verse.plugins.bind, verse.plugins.session: Rename binding-success and binding-failure to bind-success and bind-failure for consistency
Matthew Wild <mwild1@gmail.com>
parents: 43
diff changeset
22 stream:event("bind-failure", { error = condition, text = text, type = type });
9
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end);
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 stream:hook("stream-features", handle_features, 200);
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return true;
ca225a2d67b4 plugins.bind: Add plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end