Skip to content

Commit

Permalink
refactor: provider.callback is now a function instead of a getter
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `Provider.prototype.callback` is now a function instead
of a getter.
  • Loading branch information
panva committed Mar 3, 2020
1 parent 2a54e33 commit e78e573
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const configuration = {
const oidc = new Provider('http://localhost:3000', configuration);

// express/nodejs style application callback (req, res, next) for use with express apps, see /examples/express.js
oidc.callback
oidc.callback()

// koa application for use with koa apps, see /examples/koa.js
oidc.app
Expand Down
2 changes: 1 addition & 1 deletion certification/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ render(provider.app, {
root: path.join(__dirname, '..', 'example', 'views'),
});
provider.use(routes(provider).routes());
const server = https.createServer(pem, provider.callback);
const server = https.createServer(pem, provider.callback());
server.listen(PORT);
2 changes: 1 addition & 1 deletion certification/fapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ if (SUITE_BASE_URL === OFFICIAL_CERTIFICATION) {
requestCert: true,
rejectUnauthorized: false,
...pem,
}, fapi.callback);
}, fapi.callback());

server.listen(PORT);
}
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const configuration = {
const oidc = new Provider('http://localhost:3000', configuration);

// express/nodejs style application callback (req, res, next) for use with express apps, see /examples/express.js
oidc.callback
oidc.callback()

// koa application for use with koa apps, see /examples/koa.js
oidc.app
Expand Down Expand Up @@ -270,7 +270,7 @@ provider.registerGrantType(grantType, tokenExchangeHandler, parameters, allowedD


## Registering module middlewares (helmet, ip-filters, rate-limiters, etc)
When using `provider.app` or `provider.callback` as a mounted application in your own koa or express
When using `provider.app` or `provider.callback()` as a mounted application in your own koa or express
stack just follow the respective module's documentation. However, when using the `provider.app` Koa
instance directly to register i.e. koa-helmet you must push the middleware in
front of oidc-provider in the middleware stack.
Expand Down Expand Up @@ -346,7 +346,7 @@ Note: if you mount oidc-provider to a path it's likely you will have to also upd
### to a `connect` application
```js
// assumes connect ^3.0.0
connectApp.use('/oidc', oidc.callback);
connectApp.use('/oidc', oidc.callback());
```

### to a `fastify` application
Expand All @@ -356,13 +356,13 @@ await app.register(require('fastify-express'));
// or
// await app.register(require('middie'));

fastifyApp.use('/oidc', oidc.callback);
fastifyApp.use('/oidc', oidc.callback());
```

### to a `hapi` application
```js
// assumes @hapi/hapi ^20.0.0
const { callback } = oidc;
const callback = oidc.callback();
hapiApp.route({
path: `/oidc/{any*}`,
method: '*',
Expand Down Expand Up @@ -403,7 +403,7 @@ export class OidcController {
### to an `express` application
```js
// assumes express ^4.0.0
expressApp.use('/oidc', oidc.callback);
expressApp.use('/oidc', oidc.callback());
```

### to a `koa` application
Expand Down
2 changes: 1 addition & 1 deletion example/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let server;
}

routes(app, provider);
app.use(provider.callback);
app.use(provider.callback());
server = app.listen(PORT, () => {
console.log(`application is listening on port ${PORT}, check its /.well-known/openid-configuration`);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/oidc_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = function getContext(provider) {
this.ctx.req.originalUrl.indexOf(this.ctx.request.url),
))
|| this.ctx.mountPath // koa-mount
|| this.ctx.req.baseUrl // expressApp.use('/op', provider.callback);
|| this.ctx.req.baseUrl // expressApp.use('/op', provider.callback());
|| ''; // no mount

return url.resolve(this.ctx.href, provider.pathFor(name, { mountPath, ...opt }));
Expand Down
3 changes: 1 addition & 2 deletions lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ class Provider extends events.EventEmitter {
return instance(this).app;
}

// TODO: in v7.x make this a function
get callback() {
callback() {
return this.app.callback();
}

Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,20 @@ module.exports = function testHelper(dir, {
}
case 'express': {
const app = new Express();
app.use(mountTo, provider.callback);
app.use(mountTo, provider.callback());
global.server.on('request', app);
break;
}
case 'connect': {
const app = new Connect();
app.use(mountTo, provider.callback);
app.use(mountTo, provider.callback());
global.server.on('request', app);
break;
}
case 'fastify': {
const app = new Fastify();
await app.register(middie);
app.use(mountTo, provider.callback);
app.use(mountTo, provider.callback());
await new Promise((resolve) => global.server.close(resolve));
await app.listen(port);
global.server = app.server;
Expand All @@ -429,7 +429,7 @@ module.exports = function testHelper(dir, {
case 'hapi': {
const Hapi = require('@hapi/hapi'); // eslint-disable-line global-require
const app = new Hapi.Server({ port });
const { callback } = provider;
const callback = provider.callback();
app.route({
path: `${mountTo}/{any*}`,
method: '*',
Expand Down Expand Up @@ -460,7 +460,7 @@ module.exports = function testHelper(dir, {
break;
}
default:
global.server.on('request', provider.callback);
global.server.on('request', provider.callback());
}

agent = supertest(global.server);
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,6 @@ export class Provider extends events.EventEmitter {

readonly issuer: string;
readonly app: Koa;
readonly callback: (req: http.IncomingMessage | http2.Http2ServerRequest, res: http.ServerResponse | http2.Http2ServerResponse) => void;

env?: Koa['env'];
proxy?: Koa['proxy'];
Expand All @@ -1181,6 +1180,7 @@ export class Provider extends events.EventEmitter {
maxIpsCount?: number;
keys?: Koa['keys'];
listen: Koa['listen'];
callback: Koa['callback'];

interactionResult(
req: http.IncomingMessage | http2.Http2ServerRequest,
Expand Down

0 comments on commit e78e573

Please sign in to comment.