Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-oauth-server

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-oauth-server - npm Package Compare versions

Comparing version 2.0.0-b1 to 2.0.0-b2

9

index.js

@@ -28,2 +28,5 @@ 'use strict';

this.continueMiddleware = options.continueMiddleware ? true : false;
delete options.continueMiddleware;
this.server = new NodeOAuthServer(options);

@@ -82,2 +85,5 @@ }

res.locals.oauth = { code: code };
if (this.continueMiddleware) {
next();
}
})

@@ -114,2 +120,5 @@ .then(function() {

res.locals.oauth = { token: token };
if (this.continueMiddleware) {
next();
}
})

@@ -116,0 +125,0 @@ .then(function() {

2

package.json
{
"name": "express-oauth-server",
"version": "2.0.0-b1",
"version": "2.0.0-b2",
"description": "OAuth provider for express",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -37,1 +37,26 @@ # Express OAuth Server [![Build Status](https://travis-ci.org/oauthjs/express-oauth-server.png?branch=master)](https://travis-ci.org/oauthjs/express-oauth-server)

```
## Options
```
var options = {
useErrorHandler: false,
continueMiddleWare: false,
}
```
* `useErrorHandler`
(_type: boolean_ default: false)
If false, an error response will be rendered by this component.
Set this value to true to allow your own express error handler to handle the error.
* `continueMiddleware`
(_type: boolean default: false_)
The `authorize()` and `token()` middlewares will both render their
result to the response and end the pipeline.
next() will only be called if this is set to true.
**Note:** You cannot modify the response since the headers have already been sent.
`authenticate()` does not modify the response and will always call next()

@@ -14,2 +14,3 @@ 'use strict';

var should = require('should');
var sinon = require('sinon');

@@ -95,4 +96,4 @@ /**

app.use(oauth.authenticate());
app.use(function(req, res, next) {
var spy = sinon.spy(function(req, res, next) {
res.locals.oauth.token.should.equal(token);

@@ -102,2 +103,3 @@

});
app.use(spy);

@@ -107,3 +109,6 @@ request(app.listen())

.set('Authorization', 'Bearer foobar')
.end(done);
.expect(200, function(){
spy.called.should.be.true;
done();
});
});

@@ -126,11 +131,11 @@ });

};
var oauth = new ExpressOAuthServer({ model: model });
var oauth = new ExpressOAuthServer({ model: model, continueMiddleware: true });
app.use(oauth.authorize());
app.use(function(req, res, next) {
var spy = sinon.spy(function(req, res, next) {
res.locals.oauth.code.should.equal(code);
next();
});
app.use(spy);

@@ -141,3 +146,6 @@ request(app.listen())

.send({ client_id: 12345, response_type: 'code' })
.end(done);
.expect(200, function(){
spy.called.should.be.true;
done();
});
});

@@ -219,7 +227,6 @@

};
var oauth = new ExpressOAuthServer({ model: model });
var oauth = new ExpressOAuthServer({ model: model, continueMiddleware: true });
app.use(oauth.token());
app.use(function(req, res, next) {
var spy = sinon.spy(function(req, res, next) {
res.locals.oauth.token.should.equal(token);

@@ -229,2 +236,3 @@

});
app.use(spy);

@@ -235,3 +243,6 @@ request(app.listen())

.expect({ access_token: 'foobar', token_type: 'Bearer' })
.end(done);
.expect(200, function(){
spy.called.should.be.true;
done();
});
});

@@ -251,6 +262,6 @@

};
var oauth = new ExpressOAuthServer({ model: model });
var spy = sinon.spy();
var oauth = new ExpressOAuthServer({ model: model, continueMiddleware: true });
app.use(oauth.token());
request(app.listen())

@@ -257,0 +268,0 @@ .post('/')

@@ -64,3 +64,2 @@ 'use strict';

oauth.server.authenticate.restore();
done();

@@ -72,3 +71,4 @@ });

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

@@ -79,2 +79,3 @@

app.use(oauth.authorize());
app.use(nextMiddleware);

@@ -90,3 +91,27 @@ request(app.listen())

oauth.server.authorize.restore();
nextMiddleware.called.should.be.false();
done();
});
});
it('should call `authorize()` and continue middleware chain', function(done) {
var nextMiddleware = sinon.spy()
var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true });
sinon.stub(oauth.server, 'authorize').returns({});
app.use(oauth.authorize());
app.use(nextMiddleware);
request(app.listen())
.get('/')
.end(function() {
oauth.server.authorize.callCount.should.equal(1);
oauth.server.authorize.firstCall.args.should.have.length(3);
oauth.server.authorize.firstCall.args[0].should.be.an.instanceOf(Request);
oauth.server.authorize.firstCall.args[1].should.be.an.instanceOf(Response);
should.not.exist(oauth.server.authorize.firstCall.args[2]);
oauth.server.authorize.restore();
nextMiddleware.called.should.be.true();
nextMiddleware.args[0].length.should.eql(3);
done();

@@ -112,3 +137,2 @@ });

oauth.server.authorize.restore();
done();

@@ -120,3 +144,4 @@ });

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

@@ -127,2 +152,3 @@

app.use(oauth.token());
app.use(nextMiddleware);

@@ -138,3 +164,27 @@ request(app.listen())

oauth.server.token.restore();
nextMiddleware.called.should.be.false();
done();
});
});
it('should call `token()` and continue middleware chain', function(done) {
var nextMiddleware = sinon.spy()
var oauth = new ExpressOAuthServer({ model: {}, continueMiddleware: true });
sinon.stub(oauth.server, 'token').returns({});
app.use(oauth.token());
app.use(nextMiddleware);
request(app.listen())
.get('/')
.end(function() {
oauth.server.token.callCount.should.equal(1);
oauth.server.token.firstCall.args.should.have.length(3);
oauth.server.token.firstCall.args[0].should.be.an.instanceOf(Request);
oauth.server.token.firstCall.args[1].should.be.an.instanceOf(Response);
should.not.exist(oauth.server.token.firstCall.args[2]);
oauth.server.token.restore();
nextMiddleware.called.should.be.true();
nextMiddleware.args[0].length.should.eql(3);
done();

@@ -160,3 +210,2 @@ });

oauth.server.token.restore();
done();

@@ -163,0 +212,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc