From 307b385a98d56e95657797227660cf2ec080a664 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 1 Dec 2026 21:17:08 -0500 Subject: [PATCH] fix: Show a clear notice when the OAuth provider is unavailable (#14845) * fix: Show provider outage notice instead of reporting OAuth 5xx to Sentry * trans --- app/scenes/Login/components/Notices.tsx | 27 +++++++++++++++++++-- server/middlewares/passport.ts | 28 ++++++++++++++++------ shared/i18n/locales/en_US/translation.json | 1 + 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/app/scenes/Login/components/Notices.tsx b/app/scenes/Login/components/Notices.tsx index 85fd0f12d7..c1fc23acb8 100644 --- a/app/scenes/Login/components/Notices.tsx +++ b/app/scenes/Login/components/Notices.tsx @@ -2,8 +2,15 @@ import { WarningIcon } from "outline-icons"; import { Trans } from "react-i18next"; import Notice from "~/components/Notice"; import useQuery from "~/hooks/useQuery"; +import useStores from "~/hooks/useStores"; -function Message({ notice }: { notice: string }) { +function Message({ + notice, + providerName, +}: { + notice: string; + providerName?: string; +}) { switch (notice) { case "invalid-code": return ( @@ -68,6 +75,16 @@ function Message({ notice }: { notice: string }) { try again in a few minutes. ); + case "provider-unavailable": + if (providerName) { + return ( + + ); + } + // falls through case "auth-error": case "state-mismatch": return ( @@ -127,15 +144,21 @@ function Message({ notice }: { notice: string }) { export function Notices() { const query = useQuery(); + const { auth } = useStores(); const notice = query.get("notice"); + // Resolve the name from config so that query text is never displayed. + const providerName = auth.config?.providers.find( + (provider) => provider.id === query.get("provider") + )?.name; + if (!notice) { return null; } return ( }> - + ); } diff --git a/server/middlewares/passport.ts b/server/middlewares/passport.ts index faee69588f..abb0273e25 100644 --- a/server/middlewares/passport.ts +++ b/server/middlewares/passport.ts @@ -59,19 +59,27 @@ export default function createMiddleware(providerName: string) { }, async (err, user, result: AuthenticationResult) => { if (err) { + const oauthError = + err instanceof InternalOAuthError ? err.oauthError : undefined; + const providerUnavailable = oauthError?.statusCode >= 500; + // TokenError / AuthorizationError surface input problems reported by // the upstream OAuth provider (expired or already-redeemed codes, - // access_denied, etc). They are not server bugs, so log at warn - // level and skip the error reporter. - if (err instanceof TokenError || err instanceof AuthorizationError) { + // access_denied, etc) and 5xx responses are provider outages. They + // are not server bugs, so log at warn level and skip the error reporter. + if ( + err instanceof TokenError || + err instanceof AuthorizationError || + providerUnavailable + ) { Logger.warn(`OAuth error during authentication: ${err.message}`, { code: err.code, + statusCode: oauthError?.statusCode, }); + } else if (oauthError instanceof Error) { + Logger.error("Error during authentication", oauthError); } else { - Logger.error( - "Error during authentication", - err instanceof InternalOAuthError ? err.oauthError : err - ); + Logger.error("Error during authentication", err, { oauthError }); } if (err.id) { @@ -111,6 +119,12 @@ export default function createMiddleware(providerName: string) { ); } + if (providerUnavailable) { + return ctx.redirect( + `/?notice=provider-unavailable&provider=${encodeURIComponent(providerName)}` + ); + } + if (env.isDevelopment) { throw err; } diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index c72fb06207..64741997da 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -1196,6 +1196,7 @@ "We could not read the user info supplied by your identity provider.": "We could not read the user info supplied by your identity provider.", "Your account uses email sign-in. Please sign in with email to continue.": "Your account uses email sign-in. Please sign in with email to continue.", "An email sign-in link was recently sent. Please check your inbox or try again in a few minutes.": "An email sign-in link was recently sent. Please check your inbox or try again in a few minutes.", + "{{ providerName }} returned an error. This is a temporary problem with {{ providerName }}, please try again in a few minutes.": "{{ providerName }} returned an error. This is a temporary problem with {{ providerName }}, please try again in a few minutes.", "Authentication failed – we were unable to sign you in at this time. Please try again.": "Authentication failed – we were unable to sign you in at this time. Please try again.", "Authentication failed – you do not have permission to access this workspace.": "Authentication failed – you do not have permission to access this workspace.", "Sorry, it looks like that sign-in link is no longer valid. Please try requesting another.": "Sorry, it looks like that sign-in link is no longer valid. Please try requesting another.",