Software /
code /
prosody-modules
Annotate
mod_json_streams/strophe.jsonstreams.js @ 5193:2bb29ece216b
mod_http_oauth2: Implement stateless dynamic client registration
Replaces previous explicit registration that required either the
additional module mod_adhoc_oauth2_client or manually editing the
database. That method was enough to have something to test with, but
would not probably not scale easily.
Dynamic client registration allows creating clients on the fly, which
may be even easier in theory.
In order to not allow basically unauthenticated writes to the database,
we implement a stateless model here.
per_host_key := HMAC(config -> oauth2_registration_key, hostname)
client_id := JWT { client metadata } signed with per_host_key
client_secret := HMAC(per_host_key, client_id)
This should ensure everything we need to know is part of the client_id,
allowing redirects etc to be validated, and the client_secret can be
validated with only the client_id and the per_host_key.
A nonce injected into the client_id JWT should ensure nobody can submit
the same client metadata and retrieve the same client_secret
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Mar 2023 21:14:19 +0100 |
parent | 1343:7dbde05b48a9 |
rev | line source |
---|---|
351
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 /* jsonstreams plugin |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 ** |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 ** This plugin upgrades Strophe to support XEP-0295: JSON Encodings for XMPP |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 ** |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 */ |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 Strophe.addConnectionPlugin('jsonstreams', { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 init: function (conn) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 var parseXMLString = function(xmlStr) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 var xmlDoc = null; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 if (window.ActiveXObject) { |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
352
diff
changeset
|
14 xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); |
351
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 xmlDoc.async=false; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 xmlDoc.loadXML(xmlStr); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 } else { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 var parser = new DOMParser(); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 xmlDoc = parser.parseFromString(xmlStr, "text/xml"); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 return xmlDoc; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 // replace Strophe.Request._newXHR with new jsonstreams version |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 // if JSON is detected |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 if (window.JSON) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 var _newXHR = Strophe.Request.prototype._newXHR; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 Strophe.Request.prototype._newXHR = function () { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 var _xhr = _newXHR.apply(this, arguments); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 var xhr = { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 readyState: 0, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 responseText: null, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 responseXML: null, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 status: null, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 open: function(a, b, c) { return _xhr.open(a, b, c) }, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 abort: function() { _xhr.abort(); }, |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 send: function(data) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 data = JSON.stringify({"s":data}); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 return _xhr.send(data); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 }; |
352
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
42 var req = this; |
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
43 xhr.onreadystatechange = this.func.bind(null, this); |
351
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 _xhr.onreadystatechange = function() { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 xhr.readyState = _xhr.readyState; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 if (xhr.readyState != 4) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 xhr.status = 0; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 xhr.responseText = ""; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 xhr.responseXML = null; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 } else { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 xhr.status = _xhr.status; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 xhr.responseText = _xhr.responseText; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 xhr.responseXML = _xhr.responseXML; |
352
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
54 if (_xhr.responseText && !(_xhr.responseXML |
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
55 && _xhr.responseXML.documentElement |
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
56 && _xhr.responseXML.documentElement.tagName != "parsererror")) { |
351
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 var data = JSON.parse(_xhr.responseText); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 if (data && data.s) { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 xhr.responseText = data.s; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 xhr.responseXML = parseXMLString(data.s); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 } |
352
0b4fe47e648d
mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
Waqas Hussain <waqas20@gmail.com>
parents:
351
diff
changeset
|
64 if ("function" == typeof xhr.onreadystatechange) { xhr.onreadystatechange(req); } |
351
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 return xhr; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 }; |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 } else { |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 Strophe.error("jsonstreams plugin loaded, but JSON not found." + |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 " Falling back to native XHR implementation."); |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 } |
85d3c04c64f6
mod_json_streams/strophe.jsonstreams.js: A strophe.js plugin to make it work.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 }); |