Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Various bugfixes and style adjustments #110

Merged
merged 17 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions boot/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
* Module dependencies
*/

var cwd = process.cwd()
var fs = require('fs')
var path = require('path')
var jwks = require(path.join(__dirname, '..', 'lib', 'jwks'))
var cwd = process.cwd();
var fs = require('fs');
var path = require('path');
var jwks = require(path.join(__dirname, '..', 'lib', 'jwks'));

/**
* Keys
*/

var keys = {}
var privateKey, publicKey
var defaultPublicKeyFile = path.join(cwd, 'config', 'keys', 'public.pem')
var defaultPrivateKeyFile = path.join(cwd, 'config', 'keys', 'private.pem')
var keys = {};
var privateKey, publicKey;
var defaultPublicKeyFile = path.join(cwd, 'config', 'keys', 'public.pem');
var defaultPrivateKeyFile = path.join(cwd, 'config', 'keys', 'private.pem');

/**
* Look for environment variables.
*/

if (process.env.ANVIL_CONNECT_PRIVATE_KEY) {
privateKey = new Buffer(process.env.ANVIL_CONNECT_PRIVATE_KEY, 'base64').toString('ascii')
privateKey = new Buffer(process.env.ANVIL_CONNECT_PRIVATE_KEY, 'base64').toString('ascii');
}

if (process.env.ANVIL_CONNECT_PUBLIC_KEY) {
publicKey = new Buffer(process.env.ANVIL_CONNECT_PUBLIC_KEY, 'base64').toString('ascii')
publicKey = new Buffer(process.env.ANVIL_CONNECT_PUBLIC_KEY, 'base64').toString('ascii');
}

/**
Expand All @@ -34,24 +34,24 @@ if (process.env.ANVIL_CONNECT_PUBLIC_KEY) {
*/

try {
privateKey = fs.readFileSync(defaultPrivateKeyFile).toString('ascii')
publicKey = fs.readFileSync(defaultPublicKeyFile).toString('ascii')
privateKey = fs.readFileSync(defaultPrivateKeyFile).toString('ascii');
publicKey = fs.readFileSync(defaultPublicKeyFile).toString('ascii');
} catch (err) {}

/**
* Ensure the key pair has been loaded
*/

if (!privateKey || !publicKey) {
console.log('Cannot load keypair')
process.exit(1)
console.log('Cannot load keypair');
process.exit(1);
}

/**
* Export
*/

keys.privateKey = privateKey
keys.publicKey = publicKey
keys.jwks = jwks(publicKey)
module.exports = keys
keys.privateKey = privateKey;
keys.publicKey = publicKey;
keys.jwks = jwks(publicKey);
module.exports = keys;
4 changes: 2 additions & 2 deletions boot/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var URL = require('url')
, redis = require('redis');

module.exports = function (config) {
var client, url, port, host, db, pass;
var client, url, port, host, db, auth, options;

if (config = config || {}) {
try {
Expand All @@ -15,7 +15,7 @@ module.exports = function (config) {

options = {
no_ready_check: true
}
};

client = redis.createClient(port, host, options);

Expand Down
4 changes: 2 additions & 2 deletions boot/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ module.exports = function (server) {
*/

server.use(cookieParser(settings.cookie_secret));
server.use(bodyParser.urlencoded({ extended: false }))
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());


/**
Expand Down
2 changes: 1 addition & 1 deletion lib/time-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
exports.nowSeconds = function (deltaSecs) {
var secs = Date.now();
var secs = Math.round(secs / 1000);
secs = Math.round(secs / 1000);
var secsStr;

if (deltaSecs) {
Expand Down
6 changes: 2 additions & 4 deletions models/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,6 @@ Client.prototype.authorizedScope = function (callback) {
*/

Client.listAuthorizedByUser = function (userId, options, callback) {
var index = 'users:' + userId + ':clients';

if (!callback) {
callback = options;
options = {};
Expand Down Expand Up @@ -731,7 +729,7 @@ Client.prototype.configuration = function (settings, token) {
configuration.registration_client_uri = registrationClientUri;

if (token) {
configuration.registration_access_token = token
configuration.registration_access_token = token;
}

return configuration;
Expand Down Expand Up @@ -909,7 +907,7 @@ var authenticators = {
}

Client.get(clientId, function (err, client) {
if (err) { return next(err); }
if (err) { return callback(err); }

// Unknown client
if (!client) {
Expand Down
3 changes: 2 additions & 1 deletion models/ClientToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var JWT = require('anvil-connect-jwt')
, nowSeconds = require('../lib/time-utils').nowSeconds
;


/**
Expand Down Expand Up @@ -53,7 +54,7 @@ ClientToken.issue = function (claims, privateKey, callback) {
var jwt = token.encode(privateKey);
return callback(null, jwt);
} catch (err) {
callback(err)
callback(err);
//callback(new Error('Unable to issue client access token'));
}
};
Expand Down
2 changes: 1 addition & 1 deletion models/UserApplications.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function userApplications (user, callback) {
Client.__client.zrevrange(index, 0, -1, function (err, ids) {
if (err) { return done(err); }
done(null, ids);
})
});
},

}, function (err, results) {
Expand Down
4 changes: 2 additions & 2 deletions oidc/signout.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function signout (req, res, next) {
'Pragma': 'no-cache'
});

res.send(204);
res.sendStatus(204);
}

// logout and redirect
Expand Down Expand Up @@ -83,7 +83,7 @@ function signout (req, res, next) {
'Pragma': 'no-cache'
});

res.send(204);
res.sendStatus(204);
}
}

Expand Down
6 changes: 3 additions & 3 deletions oidc/verifyClientRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ function verifyClientRegistration (req, res, next) {


function hasScope (claims, scope) {
var cscope = claims && claims.scope
var cscope = claims && claims.scope;

// false if there's no scope
if (!cscope) { return false; }

// split the values if they're strings
if (typeof cscope === 'string') { cscope = cscope.split(' ') }
if (typeof cscope === 'string') { cscope = cscope.split(' '); }

// check if the token has any of the prescribed scope values
return cscope.some(function (s) {
return (scope.indexOf(s) !== -1) ? true : false;
return (scope && scope.indexOf(s) !== -1) ? true : false;
});
}

Expand Down
4 changes: 2 additions & 2 deletions oidc/verifyClientToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function verifyClientToken (req, res, next) {
// decoded successfully
else {
// validate token
req.token = token
next()
req.token = token;
next();
}
}
};
Expand Down
1 change: 0 additions & 1 deletion protocols/OAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ function signatureBaseStringURI (uri) {
, protocol = url.protocol
, hostname = url.hostname
, pathname = url.pathname
, search = url.search
, port = ''
, result = ''
;
Expand Down
12 changes: 6 additions & 6 deletions protocols/OpenID.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function verifier (req, identifier, userInfo, done) {
// Raw OpenID Provider response should be stored
// for consistency with other protocols.
var auth = {
id: request.query['openid.identity'],
id: req.query['openid.identity'],
req_query: req.query
};

userInfo.id = request.query['openid.identity'];
userInfo.name = request.query['openid.ext2.value.fullname'];
userInfo.givenName = request.query['openid.ext2.value.firstname'];
userInfo.familyName = request.query['openid.ext2.value.lastname'];
userInfo.email = request.query['openid.ext2.value.email'];
userInfo.id = req.query['openid.identity'];
userInfo.name = req.query['openid.ext2.value.fullname'];
userInfo.givenName = req.query['openid.ext2.value.firstname'];
userInfo.familyName = req.query['openid.ext2.value.lastname'];
userInfo.email = req.query['openid.ext2.value.email'];

User.connect(req, auth, userInfo, function (err, user) {
if (err) { return done(err); }
Expand Down
2 changes: 1 addition & 1 deletion providers/mailchimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ module.exports = function (config) {
};

function localhost(issuer) {
return issuer.replace('localhost', '127.0.0.1')
return issuer.replace('localhost', '127.0.0.1');
}
Empty file removed providers/templates/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion routes/authorizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (server) {

AccessToken.revoke(uid, cid, function (err, confirm) {
if (err) { return next(err); }
res.status(204).send()
res.sendStatus(204);
});
});

Expand Down
1 change: 1 addition & 0 deletions routes/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var oidc = require('../oidc')
, Client = require('../models/Client')
, ClientToken = require('../models/ClientToken')
, ValidationError = require('../errors/ValidationError')
, NotFoundError = require('../errors/NotFoundError')
;


Expand Down
10 changes: 0 additions & 10 deletions routes/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,5 @@ module.exports = function (server) {

server.post('/signin', handler);

// Only register the password signin post handler
// if the password protocol is enabled.
// if (settings.providers.password === true) {
// server.post('/signin', handler);
// } else {
// server.post('/signin', function (req, res, next) {
// next(new PasswordsDisabledError());
// });
// }

};

1 change: 1 addition & 0 deletions routes/userinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var oidc = require('../oidc')
, settings = require('../boot/settings')
, User = require('../models/User')
, NotFoundError = require('../errors/NotFoundError')
;


Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ module.exports = server;
*/

if (!module.parent) {
server.start()
server.start();
}

8 changes: 4 additions & 4 deletions test/oidc/signout.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe 'Signout', ->
logout: sinon.spy()
res =
set: sinon.spy()
send: sinon.spy()
sendStatus: sinon.spy()
redirect: sinon.spy()
next = sinon.spy()
signout(req, res, next)
Expand All @@ -137,7 +137,7 @@ describe 'Signout', ->
req.session.opbs.should.not.equal opbs

it 'should respond 204', ->
res.send.should.have.been.calledWith 204
res.sendStatus.should.have.been.calledWith 204


describe 'and valid uri', ->
Expand Down Expand Up @@ -235,7 +235,7 @@ describe 'Signout', ->
logout: sinon.spy()
res =
set: sinon.spy()
send: sinon.spy()
sendStatus: sinon.spy()
next = sinon.spy()
signout(req, res, next)

Expand All @@ -246,7 +246,7 @@ describe 'Signout', ->
req.session.opbs.should.not.equal opbs

it 'should respond 204', ->
res.send.should.have.been.calledWith 204
res.sendStatus.should.have.been.calledWith 204

it 'should respond with Cache-Control header', ->
res.set.should.have.been.calledWith sinon.match({
Expand Down