Renamed "data" to "socket", updated deps
This commit is contained in:
24
lib/index.js
24
lib/index.js
@ -112,15 +112,15 @@ function authorize(options, onConnection) {
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
success: function(data, accept){
|
||||
if (data.request) {
|
||||
success: function(socket, accept){
|
||||
if (socket.request) {
|
||||
accept();
|
||||
} else {
|
||||
accept(null, true);
|
||||
}
|
||||
},
|
||||
fail: function(error, data, accept){
|
||||
if (data.request) {
|
||||
fail: function(error, socket, accept){
|
||||
if (socket.request) {
|
||||
accept(error);
|
||||
} else {
|
||||
accept(null, false);
|
||||
@ -130,9 +130,9 @@ function authorize(options, onConnection) {
|
||||
|
||||
var auth = xtend(defaults, options);
|
||||
|
||||
return function(data, accept){
|
||||
return function(socket, accept){
|
||||
var token, error;
|
||||
var req = data.request || data;
|
||||
var req = socket.request || socket;
|
||||
var authorization_header = (req.headers || {}).authorization;
|
||||
|
||||
if (authorization_header) {
|
||||
@ -148,7 +148,7 @@ function authorize(options, onConnection) {
|
||||
error = new UnauthorizedError('credentials_bad_format', {
|
||||
message: 'Format is Authorization: Bearer [token]'
|
||||
});
|
||||
return auth.fail(error, data, accept);
|
||||
return auth.fail(error, socket, accept);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,25 +164,25 @@ function authorize(options, onConnection) {
|
||||
error = new UnauthorizedError('credentials_required', {
|
||||
message: 'No Authorization header was found'
|
||||
});
|
||||
return auth.fail(error, data, accept);
|
||||
return auth.fail(error, socket, accept);
|
||||
}
|
||||
|
||||
var onJwtVerificationReady = function(err, decoded) {
|
||||
|
||||
if (err) {
|
||||
error = new UnauthorizedError(err.code || 'invalid_token', err);
|
||||
return auth.fail(error, data, accept);
|
||||
return auth.fail(error, socket, accept);
|
||||
}
|
||||
|
||||
data[options.decodedPropertyName] = decoded;
|
||||
socket[options.decodedPropertyName] = decoded;
|
||||
|
||||
return auth.success(data, accept);
|
||||
return auth.success(socket, accept);
|
||||
};
|
||||
|
||||
var onSecretReady = function(err, secret) {
|
||||
if (err) {
|
||||
error = new UnauthorizedError(err.code || 'invalid_secret', err);
|
||||
return auth.fail(error, data, accept);
|
||||
return auth.fail(error, socket, accept);
|
||||
}
|
||||
|
||||
jwt.verify(token, secret, options, onJwtVerificationReady);
|
||||
|
Reference in New Issue
Block a user