Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions examples/mongodb/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,21 @@ module.exports.saveToken = function(token, client, user) {
// Can't just chain `lean()` to `save()` as we did with `findOne()` elsewhere. Instead we use `Promise` to resolve the data.
return new Promise( function(resolve,reject){
accessToken.save(function(err,data){
if( err ) reject( err );
else resolve( data );
if( err ) {
reject( err );
} else {
resolve( data );
}
}) ;
}).then(function(saveResult){
// `saveResult` is mongoose wrapper object, not doc itself. Calling `toJSON()` returns the doc.
saveResult = saveResult && typeof saveResult == 'object' ? saveResult.toJSON() : saveResult;
saveResult = saveResult && typeof saveResult === 'object' ? saveResult.toJSON() : saveResult;

// Unsure what else points to `saveResult` in oauth2-server, making copy to be safe
var data = new Object();
for( var prop in saveResult ) data[prop] = saveResult[prop];
var data = {};
for( var prop in saveResult ) {
data[prop] = saveResult[prop];
}

// /oauth-server/lib/models/token-model.js complains if missing `client` and `user`. Creating missing properties.
data.client = data.clientId;
Expand Down
7 changes: 3 additions & 4 deletions test/integration/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('ExpressOAuthServer', function() {
request(app.listen())
.get('/')
.set('Authorization', 'Bearer foobar')
.expect(200, function(err, res){
.expect(200, function(err){
spy.called.should.be.True();
done(err);
});
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('ExpressOAuthServer', function() {
.post('/?state=foobiz')
.set('Authorization', 'Bearer foobar')
.send({ client_id: 12345, response_type: 'code' })
.expect(302, function(err, res){
.expect(302, function(err){
spy.called.should.be.True();
done(err);
});
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('ExpressOAuthServer', function() {
.post('/')
.send('client_id=foo&client_secret=bar&grant_type=password&username=qux&password=biz')
.expect({ access_token: 'foobar', token_type: 'Bearer' })
.expect(200, function(err, res){
.expect(200, function(err){
spy.called.should.be.True();
done(err);
});
Expand All @@ -261,7 +261,6 @@ describe('ExpressOAuthServer', function() {
return { accessToken: 'foobar', client: {}, user: {} };
}
};
var spy = sinon.spy();
var oauth = new ExpressOAuthServer({ model: model, continueMiddleware: true });

app.use(oauth.token());
Expand Down
10 changes: 5 additions & 5 deletions test/unit/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ExpressOAuthServer', function() {
oauth.server.authenticate.firstCall.args.should.have.length(3);
oauth.server.authenticate.firstCall.args[0].should.be.an.instanceOf(Request);
oauth.server.authenticate.firstCall.args[1].should.be.an.instanceOf(Response);
should.not.exist(oauth.server.authenticate.firstCall.args[2])
should.not.exist(oauth.server.authenticate.firstCall.args[2]);
oauth.server.authenticate.restore();

done();
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('ExpressOAuthServer', function() {

describe('authorize()', function() {
it('should call `authorize()` and end middleware execution', function(done) {
var nextMiddleware = sinon.spy()
var nextMiddleware = sinon.spy();
var oauth = new ExpressOAuthServer({ model: {} });

sinon.stub(oauth.server, 'authorize').returns({});
Expand All @@ -91,7 +91,7 @@ describe('ExpressOAuthServer', function() {
});

it('should call `authorize()` and continue middleware chain', function(done) {
var nextMiddleware = sinon.spy()
var nextMiddleware = sinon.spy();
var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true });

sinon.stub(oauth.server, 'authorize').returns({});
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('ExpressOAuthServer', function() {

describe('token()', function() {
it('should call `token()` and end middleware chain', function(done) {
var nextMiddleware = sinon.spy()
var nextMiddleware = sinon.spy();
var oauth = new ExpressOAuthServer({ model: {} });

sinon.stub(oauth.server, 'token').returns({});
Expand All @@ -160,7 +160,7 @@ describe('ExpressOAuthServer', function() {
});

it('should call `token()` and continue middleware chain', function(done) {
var nextMiddleware = sinon.spy()
var nextMiddleware = sinon.spy();
var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true });

sinon.stub(oauth.server, 'token').returns({});
Expand Down