Skip to content

Commit

Permalink
fix: extend interactionDetails to allow (req, res)
Browse files Browse the repository at this point in the history
fixes #517
  • Loading branch information
panva committed Aug 25, 2019
1 parent e928920 commit e1d69cf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion certification/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ module.exports = {
features: {
backchannelLogout: { enabled: true },
devInteractions: { enabled: false },
ietfJWTAccessTokenProfile: { enabled: true },
mTLS: {
enabled: true,
certificateBoundAccessTokens: true,
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ packing the results. See them used in the [step-by-step](https://github.com/panv
or [in-repo](/example) examples.


**`#provider.interactionDetails(req)`**
**`#provider.interactionDetails(req, res)`**
```js
// with express
expressApp.get('/interaction/:uid', async (req, res) => {
const details = await provider.interactionDetails(req);
const details = await provider.interactionDetails(req, res);
// ...
});

// with koa
router.get('/interaction/:uid', async (ctx, next) => {
const details = await provider.interactionDetails(ctx.req);
const details = await provider.interactionDetails(ctx.req, ctx.res);
// ...
});
```
Expand Down
8 changes: 4 additions & 4 deletions example/routes/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = (app, provider) => {
try {
const {
uid, prompt, params, session,
} = await provider.interactionDetails(req);
} = await provider.interactionDetails(req, res);

const client = await provider.Client.find(params.client_id);

Expand Down Expand Up @@ -113,7 +113,7 @@ module.exports = (app, provider) => {

app.post('/interaction/:uid/login', setNoCache, body, async (req, res, next) => {
try {
const { prompt: { name } } = await provider.interactionDetails(req);
const { prompt: { name } } = await provider.interactionDetails(req, res);
assert.equal(name, 'login');
const account = await Account.findByLogin(req.body.login);

Expand All @@ -133,7 +133,7 @@ module.exports = (app, provider) => {

app.post('/interaction/:uid/continue', setNoCache, body, async (req, res, next) => {
try {
const interaction = await provider.interactionDetails(req);
const interaction = await provider.interactionDetails(req, res);
const { prompt: { name, details } } = interaction;
assert.equal(name, 'select_account');

Expand All @@ -157,7 +157,7 @@ module.exports = (app, provider) => {

app.post('/interaction/:uid/confirm', setNoCache, body, async (req, res, next) => {
try {
const { prompt: { name, details } } = await provider.interactionDetails(req);
const { prompt: { name, details } } = await provider.interactionDetails(req, res);
assert.equal(name, 'consent');

const consent = {};
Expand Down
10 changes: 5 additions & 5 deletions example/routes/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = (provider) => {
router.get('/interaction/:uid', async (ctx, next) => {
const {
uid, prompt, params, session,
} = await provider.interactionDetails(ctx.req);
} = await provider.interactionDetails(ctx.req, ctx.res);
const client = await provider.Client.find(params.client_id);

switch (prompt.name) {
Expand Down Expand Up @@ -113,7 +113,7 @@ module.exports = (provider) => {
router.get('/interaction/callback/google', (ctx) => ctx.render('repost', { provider: 'google', layout: false }));

router.post('/interaction/:uid/login', body, async (ctx) => {
const { prompt: { name } } = await provider.interactionDetails(ctx.req);
const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res);
assert.equal(name, 'login');

const account = await Account.findByLogin(ctx.request.body.login);
Expand All @@ -132,7 +132,7 @@ module.exports = (provider) => {
});

router.post('/interaction/:uid/federated', body, async (ctx) => {
const { prompt: { name } } = await provider.interactionDetails(ctx.req);
const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res);
assert.equal(name, 'login');

const path = `/interaction/${ctx.params.uid}/federated`;
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = (provider) => {
});

router.post('/interaction/:uid/continue', body, async (ctx) => {
const interaction = await provider.interactionDetails(ctx.req);
const interaction = await provider.interactionDetails(ctx.req, ctx.res);
const { prompt: { name, details } } = interaction;
assert.equal(name, 'select_account');

Expand All @@ -199,7 +199,7 @@ module.exports = (provider) => {
});

router.post('/interaction/:uid/confirm', body, async (ctx) => {
const { prompt: { name, details } } = await provider.interactionDetails(ctx.req);
const { prompt: { name, details } } = await provider.interactionDetails(ctx.req, ctx.res);
assert.equal(name, 'consent');

const consent = {};
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ your configuration is not in effect');
async function interactionRender(ctx, next) {
const {
uid, prompt, params, session,
} = await provider.interactionDetails(ctx.req);
} = await provider.interactionDetails(ctx.req, ctx.res);
const client = await provider.Client.find(params.client_id);

let view;
Expand Down Expand Up @@ -102,7 +102,7 @@ your configuration is not in effect');
parseBody,
async function interactionSubmit(ctx, next) {
ctx.oidc.uid = ctx.params.uid;
const { prompt: { name } } = await provider.interactionDetails(ctx.req);
const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res);
switch (ctx.oidc.body.prompt) { // eslint-disable-line default-case
case 'login': {
assert.equal(name, 'login');
Expand Down
9 changes: 7 additions & 2 deletions lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ class Provider extends events.EventEmitter {
* @name interactionDetails
* @api public
*/
async interactionDetails(req) {
return getInteraction.call(this, req);
async interactionDetails(req, res) {
/* istanbul ignore if */
if (typeof res === 'undefined') { // TODO: in v7.x deprecate only req
return getInteraction.call(this, req);
}

return getInteraction.call(this, req, res);
}

/**
Expand Down

0 comments on commit e1d69cf

Please sign in to comment.