node-oauth2-server
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -8,5 +8,5 @@ var model = module.exports; | ||
{ | ||
client_id : 'thom', | ||
client_secret : 'nightworld', | ||
redirect_uri : '' | ||
clientId : 'thom', | ||
clientSecret : 'nightworld', | ||
redirectUri : '' | ||
} | ||
@@ -18,3 +18,3 @@ ], | ||
], | ||
refresh_token: [ | ||
refreshToken: [ | ||
'thom' | ||
@@ -47,3 +47,3 @@ ] | ||
var elem = oauthAccessTokens[i]; | ||
if(elem.access_token === bearerToken) { | ||
if(elem.accessToken === bearerToken) { | ||
return callback(false, elem); | ||
@@ -58,3 +58,3 @@ } | ||
var elem = oauthRefreshTokens[i]; | ||
if(elem.refresh_token === bearerToken) { | ||
if(elem.refreshToken === bearerToken) { | ||
return callback(false, elem); | ||
@@ -69,3 +69,3 @@ } | ||
var elem = oauthClients[i]; | ||
if(elem.client_id === clientId && elem.client_secret === clientSecret) { | ||
if(elem.clientId === clientId && elem.clientSecret === clientSecret) { | ||
return callback(false, elem); | ||
@@ -84,5 +84,5 @@ } | ||
oauthAccessTokens.unshift({ | ||
access_token: accessToken, | ||
client_id: clientId, | ||
user_id: userId, | ||
accessToken: accessToken, | ||
clientId: clientId, | ||
userId: userId, | ||
expires: expires | ||
@@ -96,5 +96,5 @@ }); | ||
oauthRefreshTokens.unshift({ | ||
refresh_token: refreshToken, | ||
client_id: clientId, | ||
user_id: userId, | ||
refreshToken: refreshToken, | ||
clientId: clientId, | ||
userId: userId, | ||
expires: expires | ||
@@ -101,0 +101,0 @@ }); |
@@ -25,5 +25,5 @@ /** | ||
var OAuthAccessTokensSchema = new Schema({ | ||
access_token: { type: String }, | ||
client_id: { type: String }, | ||
user_id: { type: String }, | ||
accessToken: { type: String }, | ||
clientId: { type: String }, | ||
userId: { type: String }, | ||
expires: { type: Date } | ||
@@ -33,5 +33,5 @@ }); | ||
var OAuthRefreshTokensSchema = new Schema({ | ||
refresh_token: { type: String }, | ||
client_id: { type: String }, | ||
user_id: { type: String }, | ||
refreshToken: { type: String }, | ||
clientId: { type: String }, | ||
userId: { type: String }, | ||
expires: { type: Date } | ||
@@ -41,5 +41,5 @@ }); | ||
var OAuthClientsSchema = new Schema({ | ||
client_id: { type: String }, | ||
client_secret: { type: String }, | ||
redirect_uri: { type: String } | ||
clientId: { type: String }, | ||
clientSecret: { type: String }, | ||
redirectUri: { type: String } | ||
}); | ||
@@ -71,3 +71,3 @@ | ||
OAuthAccessTokensModel.findOne({ access_token: bearerToken }, callback); | ||
OAuthAccessTokensModel.findOne({ accessToken: bearerToken }, callback); | ||
}; | ||
@@ -78,3 +78,3 @@ | ||
OAuthClientsModel.findOne({ client_id: clientId, client_secret: clientSecret }, callback); | ||
OAuthClientsModel.findOne({ clientId: clientId, clientSecret: clientSecret }, callback); | ||
}; | ||
@@ -99,5 +99,5 @@ | ||
var accessToken = new OAuthAccessTokensModel({ | ||
access_token: token, | ||
client_id: clientId, | ||
user_id: userId, | ||
accessToken: token, | ||
clientId: clientId, | ||
userId: userId, | ||
expires: expires | ||
@@ -119,3 +119,3 @@ }); | ||
/* | ||
* Required to support refresh_token grant type | ||
* Required to support refreshToken grant type | ||
*/ | ||
@@ -126,5 +126,5 @@ model.saveRefreshToken = function (token, clientId, expires, userId, callback) { | ||
var refreshToken = new OAuthRefreshTokensModel({ | ||
refresh_token: token, | ||
client_id: clientId, | ||
user_id: userId, | ||
refreshToken: token, | ||
clientId: clientId, | ||
userId: userId, | ||
expires: expires | ||
@@ -139,3 +139,3 @@ }); | ||
OAuthRefreshTokensModel.findOne({ refresh_token: refreshToken }, callback); | ||
OAuthRefreshTokensModel.findOne({ refreshToken: refreshToken }, callback); | ||
}; |
@@ -59,3 +59,3 @@ /** | ||
return self.continueAfterResponse ? next() : null; | ||
return self.config.continueAfterResponse ? next() : null; | ||
} | ||
@@ -186,2 +186,5 @@ | ||
this.res.redirect(this.client.redirectUri + '?code=' + this.authCode); | ||
if (this.config.continueAfterResponse) | ||
return done(); | ||
} |
@@ -423,4 +423,4 @@ /** | ||
if (this.continueAfterResponse) | ||
if (this.config.continueAfterResponse) | ||
done(); | ||
} |
@@ -41,3 +41,3 @@ /** | ||
this.passthroughErrors = config.passthroughErrors; | ||
this.continueAfterReponse = config.continueAfterReponse; | ||
this.continueAfterResponse = config.continueAfterResponse; | ||
@@ -44,0 +44,0 @@ this.accessTokenLifetime = config.accessTokenLifetime !== undefined ? |
{ | ||
"name": "node-oauth2-server", | ||
"description": "Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with express in node.js", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "oauth", |
@@ -79,3 +79,3 @@ # Node OAuth2 Server [![Build Status](https://travis-ci.org/thomseddon/node-oauth2-server.png?branch=2.0)](https://travis-ci.org/thomseddon/node-oauth2-server) | ||
- *boolean* **continueAfterResponse** | ||
- If true, `next` will be called even if a reponse has been sent (you probably don't want this) | ||
- If true, `next` will be called even if a response has been sent (you probably don't want this) | ||
@@ -82,0 +82,0 @@ ## Model Specification |
@@ -23,6 +23,9 @@ /** | ||
var bootstrap = function (model, params) { | ||
var bootstrap = function (model, params, continueAfterResponse) { | ||
var app = express(); | ||
app.oauth = oauth2server({ model: model || {} }); | ||
app.oauth = oauth2server({ | ||
model: model || {}, | ||
continueAfterResponse: continueAfterResponse | ||
}); | ||
@@ -195,2 +198,68 @@ app.use(express.bodyParser()); | ||
}); | ||
it('should continue after success response if continueAfterResponse = true', function (done) { | ||
var code; | ||
var app = bootstrap({ | ||
getClient: function (clientId, clientSecret, callback) { | ||
callback(false, { | ||
clientId: 'thom', | ||
redirectUri: 'http://nightworld.com' | ||
}); | ||
}, | ||
saveAuthCode: function (authCode, clientId, expires, user, callback) { | ||
should.exist(authCode); | ||
code = authCode; | ||
callback(); | ||
} | ||
}, [false, true], true); | ||
var hit = false; | ||
app.all('*', function (req, res, done) { | ||
hit = true; | ||
}); | ||
request(app) | ||
.post('/authorise') | ||
.send({ | ||
response_type: 'code', | ||
client_id: 'thom', | ||
redirect_uri: 'http://nightworld.com' | ||
}) | ||
.end(function (err, res) { | ||
if (err) return done(err); | ||
hit.should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
it('should continue after redirect response if continueAfterResponse = true', function (done) { | ||
var app = bootstrap({ | ||
getClient: function (clientId, clientSecret, callback) { | ||
callback(false, { | ||
clientId: 'thom', | ||
redirectUri: 'http://nightworld.com' | ||
}); | ||
} | ||
}, [false, false], true); | ||
var hit = false; | ||
app.all('*', function (req, res, done) { | ||
hit = true; | ||
}); | ||
request(app) | ||
.post('/authorise') | ||
.send({ | ||
response_type: 'code', | ||
client_id: 'thom', | ||
redirect_uri: 'http://nightworld.com' | ||
}) | ||
.end(function (err, res) { | ||
if (err) return done(err); | ||
hit.should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -488,4 +488,42 @@ /** | ||
}); | ||
it('should continue after response if continueAfterResponse = true', function (done) { | ||
var app = bootstrap({ | ||
model: { | ||
getClient: function (id, secret, callback) { | ||
callback(false, { clientId: 'thom' }); | ||
}, | ||
grantTypeAllowed: function (clientId, grantType, callback) { | ||
callback(false, true); | ||
}, | ||
getUser: function (uname, pword, callback) { | ||
callback(false, { id: 1 }); | ||
}, | ||
saveAccessToken: function (token, clientId, expires, user, cb) { | ||
cb(); | ||
} | ||
}, | ||
grants: ['password'], | ||
continueAfterResponse: true | ||
}); | ||
var hit = false; | ||
app.all('*', function (req, res, next) { | ||
hit = true; | ||
}); | ||
request(app) | ||
.post('/oauth/token') | ||
.set('Content-Type', 'application/x-www-form-urlencoded') | ||
.send(validBody) | ||
.expect(200) | ||
.end(function (err, res) { | ||
if (err) return done(err); | ||
hit.should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
138857
3285