express-oauth-server
Advanced tools
Comparing version 2.0.0-b3 to 2.0.0
@@ -8,3 +8,3 @@ | ||
var express = require('express'); | ||
var oauthServer = require('oauth2-server'); | ||
var oauthServer = require('express-oauth-server'); | ||
var render = require('co-views')('views'); | ||
@@ -78,3 +78,3 @@ var util = require('util'); | ||
// Get secret. | ||
app.get('/secret', app.oauth.authorize(), function(req, res) { | ||
app.get('/secret', app.oauth.authenticate(), function(req, res) { | ||
// Will require a valid access_token. | ||
@@ -81,0 +81,0 @@ res.send('Secret area'); |
@@ -19,5 +19,5 @@ | ||
accessToken: token.access_token, | ||
clientId: token.client_id, | ||
client: {id: token.client_id}, | ||
expires: token.expires, | ||
userId: token.userId | ||
user: {id: token.userId}, // could be any object | ||
}; | ||
@@ -42,3 +42,4 @@ }); | ||
clientId: oAuthClient.client_id, | ||
clientSecret: oAuthClient.client_secret | ||
clientSecret: oAuthClient.client_secret, | ||
grants: ['password'], // the list of OAuth2 grant types that should be allowed | ||
}; | ||
@@ -83,4 +84,4 @@ }); | ||
]).then(function(result) { | ||
return result.rowCount ? result.rows[0] : false; | ||
return result.rowCount ? result.rows[0] : false; // TODO return object with client: {id: clientId} and user: {id: userId} defined | ||
}); | ||
}; |
@@ -48,3 +48,2 @@ 'use strict'; | ||
var response = new Response(res); | ||
return Promise.bind(that) | ||
@@ -51,0 +50,0 @@ .then(function() { |
{ | ||
"name": "express-oauth-server", | ||
"version": "2.0.0-b3", | ||
"version": "2.0.0", | ||
"description": "OAuth provider for express", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"express": "^4.13.3", | ||
"oauth2-server": "3.0.0-b4" | ||
"oauth2-server": "3.0.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -24,3 +24,3 @@ # Express OAuth Server [![Build Status](https://travis-ci.org/oauthjs/express-oauth-server.png?branch=master)](https://travis-ci.org/oauthjs/express-oauth-server) | ||
app.oauth = new OAuthServer({ | ||
model: {}, // See https://github.com/thomseddon/node-oauth2-server for specification | ||
model: {}, // See https://github.com/oauthjs/node-oauth2-server for specification | ||
}); | ||
@@ -62,2 +62,2 @@ | ||
`authenticate()` does not modify the response and will always call next() | ||
`authenticate()` does not modify the response and will always call next() |
@@ -62,3 +62,6 @@ 'use strict'; | ||
it('should authenticate the request', function(done) { | ||
var token = { user: {} }; | ||
var tokenExpires = new Date(); | ||
tokenExpires.setDate(tokenExpires.getDate() + 1); | ||
var token = { user: {}, accessTokenExpiresAt: tokenExpires }; | ||
var model = { | ||
@@ -87,3 +90,5 @@ getAccessToken: function() { | ||
it('should cache the authorization token', function(done) { | ||
var token = { user: {} }; | ||
var tokenExpires = new Date(); | ||
tokenExpires.setDate(tokenExpires.getDate() + 1); | ||
var token = { user: {}, accessTokenExpiresAt: tokenExpires }; | ||
var model = { | ||
@@ -100,3 +105,3 @@ getAccessToken: function() { | ||
res.locals.oauth.token.should.equal(token); | ||
res.send(token); | ||
next(); | ||
@@ -109,5 +114,5 @@ }); | ||
.set('Authorization', 'Bearer foobar') | ||
.expect(200, function(){ | ||
spy.called.should.be.true; | ||
done(); | ||
.expect(200, function(err, res){ | ||
spy.called.should.be.True(); | ||
done(err); | ||
}); | ||
@@ -119,6 +124,9 @@ }); | ||
it('should cache the authorization code', function(done) { | ||
var tokenExpires = new Date(); | ||
tokenExpires.setDate(tokenExpires.getDate() + 1); | ||
var code = { authorizationCode: 123 }; | ||
var model = { | ||
getAccessToken: function() { | ||
return { user: {} }; | ||
return { user: {}, accessTokenExpiresAt: tokenExpires }; | ||
}, | ||
@@ -146,12 +154,12 @@ getClient: function() { | ||
.send({ client_id: 12345, response_type: 'code' }) | ||
.expect(200, function(){ | ||
spy.called.should.be.true; | ||
done(); | ||
.expect(302, function(err, res){ | ||
spy.called.should.be.True(); | ||
done(err); | ||
}); | ||
}); | ||
it('should return a `location` header with the error', function(done) { | ||
it('should return an error', function(done) { | ||
var model = { | ||
getAccessToken: function() { | ||
return { user: {} }; | ||
return { user: {}, accessTokenExpiresAt: new Date() }; | ||
}, | ||
@@ -173,4 +181,7 @@ getClient: function() { | ||
.send({ client_id: 12345 }) | ||
.expect('Location', 'http://example.com/?error=invalid_request&error_description=Missing%20parameter%3A%20%60response_type%60&state=foobiz') | ||
.end(done); | ||
.expect(400, function(err, res) { | ||
res.body.error.should.eql('invalid_request'); | ||
res.body.error_description.should.eql('Missing parameter: `response_type`'); | ||
done(err); | ||
}); | ||
}); | ||
@@ -181,3 +192,3 @@ | ||
getAccessToken: function() { | ||
return { user: {} }; | ||
return { user: {}, accessTokenExpiresAt: new Date() }; | ||
}, | ||
@@ -243,5 +254,5 @@ getClient: function() { | ||
.expect({ access_token: 'foobar', token_type: 'Bearer' }) | ||
.expect(200, function(){ | ||
spy.called.should.be.true; | ||
done(); | ||
.expect(200, function(err, res){ | ||
spy.called.should.be.True(); | ||
done(err); | ||
}); | ||
@@ -248,0 +259,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
80586
38
1012
1
62
+ Addedoauth2-server@3.0.0(transitive)
- Removedoauth2-server@3.0.0-b4(transitive)
Updatedoauth2-server@3.0.0