Skip to content

Commit

Permalink
feat: more ctx entities to accomodate #658
Browse files Browse the repository at this point in the history
closes #658
  • Loading branch information
panva committed Feb 28, 2020
1 parent 655ea29 commit 51b128d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/actions/authorization/interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module.exports = async function interactions(resumeRouteName, ctx, next) {
});

await interactionSession.save(cookieOptions.maxAge / 1000);
ctx.oidc.entity('Interaction', interactionSession);

const destination = await interactionUrl(ctx, interactionSession);

Expand Down
1 change: 1 addition & 0 deletions lib/actions/authorization/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function resumeAction(whitelist, resumeRouteName, ctx, ne
if (!interactionSession) {
throw new errors.SessionNotFound('interaction session not found');
}
ctx.oidc.entity('Interaction', interactionSession);

const {
result,
Expand Down
4 changes: 4 additions & 0 deletions lib/models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ module.exports = function getSession(provider) {
}
}

if (ctx.oidc instanceof provider.OIDCContext) {
ctx.oidc.entity('Session', session);
}

return session;
}

Expand Down
2 changes: 1 addition & 1 deletion test/core/basic/code.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('BASIC code', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('AuthorizationCode', 'Client', 'Account');
expect(ctx.oidc.entities).to.have.keys('AuthorizationCode', 'Client', 'Account', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/basic/none.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const scope = 'openid';

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/hybrid/code+id_token+token.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('HYBRID code+id_token+token', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode', 'AccessToken');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode', 'AccessToken', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/hybrid/code+id_token.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('HYBRID code+id_token', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/hybrid/code+token.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('HYBRID code+token', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode', 'AccessToken');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AuthorizationCode', 'AccessToken', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/implicit/id_token+token.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('IMPLICIT id_token+token', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AccessToken');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'AccessToken', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
2 changes: 1 addition & 1 deletion test/core/implicit/id_token.authorization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('IMPLICIT id_token', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'Account');
expect(ctx.oidc.entities).to.have.keys('Client', 'Account', 'Session');
}, done));

const auth = new this.AuthorizationRequest({
Expand Down
4 changes: 2 additions & 2 deletions test/end_session/end_session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('logout endpoint', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client', 'IdTokenHint');
expect(ctx.oidc.entities).to.have.keys('Client', 'IdTokenHint', 'Session');
}, done));

const params = {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('logout endpoint', () => {

it('populates ctx.oidc.entities', function (done) {
this.provider.use(this.assertOnce((ctx) => {
expect(ctx.oidc.entities).to.have.keys('Client');
expect(ctx.oidc.entities).to.have.keys('Client', 'Session');
}, done));

this.getSession().state = { secret: '123', postLogoutRedirectUri: '/', clientId: 'client' };
Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,13 @@ declare class OIDCContext {
readonly DeviceCode?: DeviceCode;
readonly IdTokenHint?: { header: AnyObject, payload: AnyObject };
readonly InitialAccessToken?: InitialAccessToken;
readonly Interaction?: Interaction;
readonly PushedAuthorizationRequest?: PushedAuthorizationRequest;
readonly RefreshToken?: RefreshToken;
readonly RegistrationAccessToken?: RegistrationAccessToken;
readonly PushedAuthorizationRequest?: PushedAuthorizationRequest;
readonly RotatedRefreshToken?: RefreshToken;
readonly RotatedRegistrationAccessToken?: RegistrationAccessToken;
readonly Session?: Session;
readonly [key: string]: any;
};
readonly claims: ClaimsParameter;
Expand Down

0 comments on commit 51b128d

Please sign in to comment.