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

OIDConfig.getLogoutRedirectUrl: use redirectURL when possible #1385

Merged
Merged
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
13 changes: 6 additions & 7 deletions app/server/lib/OIDCConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,19 @@ export class OIDCConfig {
});
}

public async getLogoutRedirectUrl(req: express.Request): Promise<string> {
const session: SessionObj|undefined = (req as RequestWithLogin).session;
const stableRedirectUri = new URL('/signed-out', getOriginUrl(req)).href;
// For IdPs that don't have end_session_endpoint, we just redirect to the logout page.
public async getLogoutRedirectUrl(req: express.Request, redirectUrl: URL): Promise<string> {
// For IdPs that don't have end_session_endpoint, we just redirect to the requested page.
if (this._skipEndSessionEndpoint) {
// Ignore redirectUrl because OIDC providers don't allow variable redirect URIs
return stableRedirectUri;
return redirectUrl.href;
}
// Alternatively, we could use a logout URL specified by configuration.
if (this._endSessionEndpoint) {
return this._endSessionEndpoint;
}
// Ignore redirectUrl because OIDC providers don't allow variable redirect URIs
const stableRedirectUri = new URL('/signed-out', getOriginUrl(req)).href;
const session: SessionObj|undefined = (req as RequestWithLogin).session;
return this._client.endSessionUrl({
// Ignore redirectUrl because OIDC providers don't allow variable redirect URIs
post_logout_redirect_uri: stableRedirectUri,
id_token_hint: session?.oidc?.idToken,
});
Expand Down
5 changes: 3 additions & 2 deletions test/server/lib/OIDCConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ describe('OIDCConfig', () => {
});

describe('getLogoutRedirectUrl', () => {
const REDIRECT_URL = new URL('http://localhost:8484/docs/signed-out');
const STABLE_LOGOUT_URL = new URL('http://localhost:8484/signed-out');
const URL_RETURNED_BY_CLIENT = 'http://localhost:8484/logout_url_from_issuer';
const ENV_VALUE_GRIST_OIDC_IDP_END_SESSION_ENDPOINT = 'http://localhost:8484/logout';
Expand All @@ -767,7 +768,7 @@ describe('OIDCConfig', () => {
env: {
GRIST_OIDC_IDP_SKIP_END_SESSION_ENDPOINT: 'true',
},
expectedUrl: STABLE_LOGOUT_URL.href,
expectedUrl: REDIRECT_URL.href,
}, {
itMsg: 'should use the GRIST_OIDC_IDP_END_SESSION_ENDPOINT when it is set',
env: {
Expand Down Expand Up @@ -803,7 +804,7 @@ describe('OIDCConfig', () => {
},
session: 'session' in ctx ? ctx.session : FAKE_SESSION
} as unknown as RequestWithLogin;
const url = await config.getLogoutRedirectUrl(req);
const url = await config.getLogoutRedirectUrl(req, REDIRECT_URL);
assert.equal(url, ctx.expectedUrl);
if (ctx.expectedLogoutParams) {
assert.isTrue(clientStub.endSessionUrl.calledOnce);
Expand Down