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: Ensure proper OIDC redirect_uri is used #192

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
16 changes: 15 additions & 1 deletion backend/src/auth/oidc-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function makeOidcStrategy (options: OidcOptions): Promise<OpenIdStr
}
}

return new OpenIdStrategy({
const strategy = new OpenIdStrategy({
name: AuthStrategy.OIDC,
config,
callbackURL: options.redirectUri,
Expand All @@ -69,4 +69,18 @@ export async function makeOidcStrategy (options: OidcOptions): Promise<OpenIdStr
.then((user: User) => done(null, user))
.catch((err: unknown) => done(err))
})

// openid-client for some reason ignores the fact that we provided a full callback URL and instead manipulates it
// based on the request URL, which may be completely wrong in case of a reverse proxy. This is a workaround.
// https://github.com/panva/openid-client/issues/733
// https://github.com/panva/openid-client/discussions/741
strategy.currentUrl = function (request) {
const callbackUrl = new URL(options.redirectUri)
const currentUrl = OpenIdStrategy.prototype.currentUrl.call(this, request)
currentUrl.protocol = callbackUrl.protocol
currentUrl.host = callbackUrl.host
return currentUrl
}

return strategy
}
Loading