Skip to content

Commit

Permalink
Exposes socket.auth. Closes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Sep 8, 2015
1 parent 671ebc5 commit 896bc00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/listener.js
Expand Up @@ -217,7 +217,7 @@ internals.Listener.prototype._publish = function (path, update) {
socket._send(update);
}
else {
route.filter(path, update.message, { credentials: socket._auth.credentials, params: sub.params }, internals.send(socket, update));
route.filter(path, update.message, { credentials: socket.auth.credentials, params: sub.params }, internals.send(socket, update));
}
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ internals.Listener.prototype._subscribe = function (path, socket, next) {

var auth = this._connection.auth.lookup({ settings: { auth: match.route.auth } }); // Create a synthetic route
if (auth) {
var credentials = socket._auth.credentials;
var credentials = socket.auth.credentials;
if (credentials) {

// Check scope
Expand Down
29 changes: 22 additions & 7 deletions lib/socket.js
Expand Up @@ -17,7 +17,8 @@ exports = module.exports = internals.Socket = function (ws, listener) {

this._ws = ws;
this._listener = listener;
this._auth = {
this.auth = {
isAuthenticated: false,
credentials: null,
artifects: null
};
Expand Down Expand Up @@ -126,7 +127,7 @@ internals.Socket.prototype._processHello = function (request) {
return this._processHelloSubscriptions(request, response);
}

if (this._auth.credentials) {
if (this.auth.isAuthenticated) {
response.error = 'Connection already authenticated';
return this._send(response);
}
Expand All @@ -140,7 +141,12 @@ internals.Socket.prototype._processHello = function (request) {
return self._send(response);
}

self._auth = res.result;
self.auth = {
isAuthenticated: true,
credentials: res.result.credentials,
artifects: res.result.artifects
};

return self._processHelloSubscriptions(request, response);
});

Expand All @@ -154,7 +160,12 @@ internals.Socket.prototype._processHello = function (request) {
return self._send(response);
}

self._auth = credentials;
self.auth = {
isAuthenticated: true,
credentials: credentials,
artifects: null
};

return self._processHelloSubscriptions(request, response);
});
};
Expand Down Expand Up @@ -227,8 +238,8 @@ internals.Socket.prototype._processRequest = function (request) {
url: path,
payload: request.payload,
headers: request.headers,
credentials: this._auth.credentials,
artifects: this._auth.artifects
credentials: this.auth.credentials,
artifects: this.auth.artifects
};

this._listener._connection.inject(shot, function (res) {
Expand Down Expand Up @@ -343,7 +354,11 @@ internals.Socket.prototype._authenticate = function (next) {

var auth = state[config.cookie];
if (auth) {
self._auth = auth;
self.auth = {
isAuthenticated: true,
credentials: auth.credentials,
artifects: auth.artifects
};
}

return next();
Expand Down

0 comments on commit 896bc00

Please sign in to comment.