Skip to content

Commit

Permalink
fix: invoking logout without credentials no longer throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredperreault-okta committed Nov 30, 2021
1 parent f32c25e commit 7d287c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ logout.forceLogoutAndRevoke = context => {
}
const revokeToken = makeTokenRevoker({ issuer, client_id, client_secret, errorHandler: makeErrorHandler(emitter) });
return async (req, res /*, next */) => {
if (!req.userContext) {
return res.sendStatus(401);
}

const tokens = req.userContext.tokens;
const revokeIfExists = token_hint => tokens[token_hint] ? revokeToken({token_hint, token: tokens[token_hint]}) : null;
const revokes = REVOKABLE_TOKENS.map( revokeIfExists );
Expand Down
9 changes: 9 additions & 0 deletions test/unit/logout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ describe('logout', () => {
};
});

describe('logout without active session', () => {
it('returns 401', async () => {
res.sendStatus = jest.fn();
req.userContext = undefined;
await logout(req, res);
expect(fetch).not.toHaveBeenCalled();
expect(res.sendStatus).toHaveBeenCalledWith(401);
});
});

describe('revoke tokens', () => {
it('revokes refresh_token', async () => {
Expand Down

0 comments on commit 7d287c0

Please sign in to comment.