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 f2d0216 commit 8600c41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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
11 changes: 10 additions & 1 deletion test/unit/logout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ 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 () => {
const tokenVal = 'sometoken';
Expand Down

0 comments on commit 8600c41

Please sign in to comment.