Comparing version 0.0.6 to 0.0.7
@@ -1,5 +0,9 @@ | ||
exports.url = 'https://api.authbase.io/v1'; | ||
global.config = { | ||
url: 'https://api.authbase.io/v1' | ||
} | ||
module.exports = { | ||
Client: require('./client'), | ||
config: global.config, | ||
API: require('./api'), | ||
Router: require('./router') | ||
}; |
@@ -1,9 +0,10 @@ | ||
var Router = require('express').Router, | ||
request = require('superagent'); | ||
var ExpressRouter = require('express').Router, | ||
request = require('superagent'), | ||
jwt = require('jwt-simple'); | ||
var RouterFactory = function(options) { | ||
var router = Router(); | ||
var Router = function(options) { | ||
var router = ExpressRouter(); | ||
router.get('/authbase/login', function(req, res) { | ||
request.get(module.parent.exports.url + '/forms/login') | ||
request.get(global.config.url + '/forms/login') | ||
.set('X-App-Id', options.id) | ||
@@ -17,8 +18,5 @@ .set('X-App-Secret', options.secret) | ||
router.get('/authbase/return', function(req, res) { | ||
var id = req.query.id; | ||
if (id) { | ||
options.onSuccess(id); | ||
} else { | ||
res.redirect('/authbase/login?error="Something went wrong!"'); | ||
} | ||
// put in try/catch after deciding where to put it | ||
req.user = jwt.decode(req.query.token, options.secret).sub; | ||
options.onAuthenticated(req, res); | ||
}); | ||
@@ -29,2 +27,2 @@ | ||
module.exports = RouterFactory; | ||
module.exports = Router; |
{ | ||
"name": "authbase", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "AuthBase API Client and Router", | ||
@@ -23,2 +23,3 @@ "main": "./lib", | ||
"dependencies": { | ||
"jwt-simple": "^0.2.0", | ||
"q": "^1.1.2", | ||
@@ -30,4 +31,4 @@ "superagent": "^0.21.0" | ||
"mocha": "^2.0.1", | ||
"nock": "^0.56.0" | ||
"nock": "^0.57.0" | ||
} | ||
} |
var expect = require('expect.js'), | ||
nock = require('nock'), | ||
AuthBase = require('../lib')('id', 'secret'); | ||
AuthBase = require('../lib').API('id', 'secret'); | ||
@@ -15,3 +15,3 @@ describe('AuthBase API Client', function() { | ||
return function() { | ||
return MockApiFactory().get(endpoint, {username: 'foo', password: 'bar'}); | ||
return MockApiFactory().get(endpoint, {email: 'foo', password: 'bar'}); | ||
} | ||
@@ -22,3 +22,3 @@ } | ||
return function() { | ||
return MockApiFactory().post(endpoint, {username: 'foo', password: 'bar'}); | ||
return MockApiFactory().post(endpoint, {email: 'foo', password: 'bar'}); | ||
} | ||
@@ -30,6 +30,6 @@ } | ||
it('should pass the user as the second argument to the callback on success', function(done) { | ||
var mock = request().reply(200, {id: '123', username: 'foo'}); | ||
var mock = request().reply(200, {id: '123', email: 'foo'}); | ||
proc({ | ||
username: 'foo', | ||
email: 'foo', | ||
password: 'bar' | ||
@@ -39,3 +39,3 @@ }, function(err, user) { | ||
expect(user.id).to.be('123'); | ||
expect(user.username).to.be('foo'); | ||
expect(user.email).to.be('foo'); | ||
@@ -49,10 +49,10 @@ // wrap it up | ||
it('should pass the user to the promise on success', function(done) { | ||
var mock = request().reply(200, {id: '123', username: 'foo'}); | ||
var mock = request().reply(200, {id: '123', email: 'foo'}); | ||
proc({ | ||
username: 'foo', | ||
email: 'foo', | ||
password: 'bar' | ||
}).then(function(user) { | ||
expect(user.id).to.be('123'); | ||
expect(user.username).to.be('foo'); | ||
expect(user.email).to.be('foo'); | ||
}).catch(function() { | ||
@@ -67,13 +67,10 @@ // shouldn't be here on success, so automatically fail | ||
it('should pass a json error if JSON object to the callback as the first argument on failure', function(done) { | ||
var mock = request().reply(400, { errors: [] }); | ||
it('should pass body to callback as error on failure', function(done) { | ||
var mock = request().reply(400, { error: 'this is an error' }); | ||
proc({ | ||
username: 'foo', | ||
email: 'foo', | ||
password: 'bar' | ||
}, function(err, user) { | ||
expect(user).to.be(undefined); | ||
expect(err.status).to.be(400); | ||
expect(err.message).to.be(undefined); | ||
expect(err.json).to.eql({ errors: [] }); | ||
mock.done(); | ||
@@ -84,18 +81,2 @@ done(); | ||
it('should pass a message if not a JSON object to the callback as the first argument on failure', function(done) { | ||
var mock = request().reply(401, 'You are unauthorized'); | ||
proc({ | ||
username: 'foo', | ||
password: 'bar' | ||
}, function(err, user) { | ||
expect(user).to.be(undefined); | ||
expect(err.status).to.be(401); | ||
expect(err.message).to.be('You are unauthorized'); | ||
expect(err.json).to.be(undefined); | ||
mock.done(); | ||
done(); | ||
}); | ||
}); | ||
it('should pass the user to the promise on failure', function(done) { | ||
@@ -105,3 +86,3 @@ var mock = request().reply(400, { errors: [] }); | ||
proc({ | ||
username: 'foo', | ||
email: 'foo', | ||
password: 'bar' | ||
@@ -120,7 +101,7 @@ }).then(function(user) { | ||
it('should pass a json error if JSON object to the promise on failure', function(done) { | ||
var mock = request().reply(400, { errors: [] }); | ||
it('should pass body to promise as error on failure', function(done) { | ||
var mock = request().reply(400, { error: 'this is an error' }); | ||
proc({ | ||
username: 'foo', | ||
email: 'foo', | ||
password: 'bar' | ||
@@ -131,5 +112,3 @@ }).then(function(user) { | ||
}).catch(function(err) { | ||
expect(err.status).to.be(400); | ||
expect(err.message).to.be(undefined); | ||
expect(err.json).to.eql({ errors: [] }); | ||
expect(err).to.eql({error: 'this is an error'}); | ||
}).finally(function() { | ||
@@ -141,21 +120,3 @@ mock.done(); | ||
it('should pass a message if not a JSON object to the promise on failure', function(done) { | ||
var mock = request().reply(401, 'You are unauthorized'); | ||
proc({ | ||
username: 'foo', | ||
password: 'bar' | ||
}).then(function(user) { | ||
// should never hit this on error, so automatically fail | ||
expect(false).to.be(true); | ||
}).catch(function(err) { | ||
expect(err.status).to.be(401); | ||
expect(err.message).to.be('You are unauthorized'); | ||
expect(err.json).to.be(undefined); | ||
}).finally(function() { | ||
mock.done(); | ||
done(); | ||
}); | ||
}); | ||
} | ||
}; | ||
} | ||
@@ -162,0 +123,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6759
3
190
1
+ Addedjwt-simple@^0.2.0
+ Addedjwt-simple@0.2.0(transitive)