diff --git a/src/server/plugins/oauth.ts b/src/server/plugins/oauth.ts index 17b9eae2..7c42fb0f 100644 --- a/src/server/plugins/oauth.ts +++ b/src/server/plugins/oauth.ts @@ -46,7 +46,8 @@ async function oauthPlugin(fastify: FastifyInstance) { logger.warn('invalid oauth request', { error: response.error, }); - return reply.internalServerError(response.error_code + ' ' + response.error); + + return reply.internalServerError(response.error); } if (response.redirect) { diff --git a/src/server/routes/api/auth/oauth/discord.ts b/src/server/routes/api/auth/oauth/discord.ts index 14cf56a3..607904f6 100644 --- a/src/server/routes/api/auth/oauth/discord.ts +++ b/src/server/routes/api/auth/oauth/discord.ts @@ -58,10 +58,17 @@ async function discordOauth({ code, host, state }: OAuthQuery, logger: Logger): }, }); - if (!res.ok) + if (!res.ok) { + const text = await res.text(); + logger.debug('discord oauth failed with a non 200 status code', { + status: res.status, + text, + }); + return { error: 'Failed to fetch access token', }; + } const json = await res.json(); diff --git a/src/server/routes/api/auth/oauth/google.ts b/src/server/routes/api/auth/oauth/google.ts index 32642b10..c487ce89 100644 --- a/src/server/routes/api/auth/oauth/google.ts +++ b/src/server/routes/api/auth/oauth/google.ts @@ -56,10 +56,17 @@ async function googleOauth({ code, host, state }: OAuthQuery, logger: Logger): P }, }); - if (!res.ok) + if (!res.ok) { + const text = await res.text(); + logger.debug('google oauth failed with a non 200 status code', { + status: res.status, + text, + }); + return { error: 'Failed to fetch access token', }; + } const json = await res.json(); if (!json.access_token) return { error: 'No access token in response' }; diff --git a/src/server/routes/api/auth/oauth/oidc.ts b/src/server/routes/api/auth/oauth/oidc.ts index 10f3d1e8..35b56111 100644 --- a/src/server/routes/api/auth/oauth/oidc.ts +++ b/src/server/routes/api/auth/oauth/oidc.ts @@ -59,10 +59,14 @@ async function oidcOauth({ code, host, state }: OAuthQuery, logger: Logger): Pro }, }); - if (!res.ok) + if (!res.ok) { + const text = await res.text(); + logger.debug('oidc oauth failed with a non 200 status code', { status: res.status, text }); + return { error: 'Failed to fetch access token', }; + } const json = await res.json(); if (!json.access_token) return { error: 'No access token in response' };