annotate plugins/ANONYMOUS.js @ 65:2e8fbf3bce7f

ANONYMOUS auth plugin.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 01 Feb 2012 21:23:28 +0100
parents
children fa184759fc41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 'use strict';
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3 /**
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net>
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17 */
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
19 Lightstring.plugins['ANONYMOUS'] = {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
20 handlers: {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
21 'mechanisms': function (stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
22 if(stanza.mechanisms.indexOf('ANONYMOUS') === -1)
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
23 return;
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
24
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
25 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
26 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
27 " mechanism='ANONYMOUS'/>"
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
28 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
30 'success': function (stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 "<stream:stream to='" + this.jid.domain + "'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 " xmlns='jabber:client'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 " xmlns:stream='http://etherx.jabber.org/streams'" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 " version='1.0'/>"
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 'features': function (stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 var that = this;
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
40 //TODO check if bind supported
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 var bind =
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
43 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 "</iq>";
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
45
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 this.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 bind,
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 //Success
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 function(stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 //Session http://xmpp.org/rfcs/rfc3921.html#session
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
51 that.jid = new Lightstring.JID(stanza.DOM.textContent);
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
52
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
53 that.send(
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
55 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" +
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
56 "</iq>",
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57 function() {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 that.emit('connected');
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
59 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
60 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 },
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 //Error
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63 function(stanza) {
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64 //TODO: Error?
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
65 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 );
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 }
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
69 };