Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#233): make post_logout_redirect_uri optional #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/lib/oauth2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,16 @@ export class OAuth2Service extends EventEmitter {
};

private endSessionHandler: RequestHandler = (req, res) => {
assertIsString(
req.query['post_logout_redirect_uri'],
'Invalid post_logout_redirect_uri type',
);

const postLogoutRedirectUri: MutableRedirectUri = {
url: new URL(req.query['post_logout_redirect_uri']),
};
let postLogoutRedirectUri: MutableRedirectUri | undefined = undefined;
if (req.query['post_logout_redirect_uri']) {
assertIsString(
req.query['post_logout_redirect_uri'],
'Invalid post_logout_redirect_uri type',
);
postLogoutRedirectUri = {
url: new URL(req.query['post_logout_redirect_uri']),
};
}

/**
* Before post logout redirect event.
Expand All @@ -395,7 +397,11 @@ export class OAuth2Service extends EventEmitter {
*/
this.emit(Events.BeforePostLogoutRedirect, postLogoutRedirectUri, req);

return res.redirect(postLogoutRedirectUri.url.href);
if (postLogoutRedirectUri !== undefined) {
return res.redirect(postLogoutRedirectUri.url.href);
} else {
return res.status(200).send('Logout successful');
}
};

private introspectHandler: RequestHandler = (req, res) => {
Expand Down
9 changes: 9 additions & 0 deletions test/oauth2-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,15 @@ describe('OAuth 2 service', () => {
expect(res.headers.location).toBe(postLogoutRedirectUri);
});

it('should show a page with the text "Logout successful" if no post_logout_redirect_uri was passed to the end_session_endpoint', async () => {
const res = await request(service.requestHandler)
.get('/endsession')
.redirects(0)
.expect(200);

expect(res.text).toBe("Logout successful");
});

it('should be able to manipulate url and query params when redirecting within post_logout_redirect_uri', async () => {
const postLogoutRedirectUri = 'http://example.com/signin?param=test';

Expand Down