Skip to content

Commit e1e4313

Browse files
committed
fix(oauth): preserve typed reauth identity errors in public projection
The public OAuth error projection from #1842 collapsed the fixed reauth-identity remediation messages (identity mismatch, unverifiable legacy identity) into the generic authentication failure, so the dashboard could no longer tell the user to sign in with the selected account. Represent both outcomes as bounded typed errors (OAuthReauthIdentityMismatchError, OAuthReauthIdentityUnverifiedError) whose messages carry no account, token, or email data, allowlist them in publicOAuthAuthenticationErrorMessage, and cover them in the projector allowlist and management status-polling regressions. Resolves the unresolved P2 review on #1842. Credit: original redaction work by @luvs01 in #1842.
1 parent d5dbb28 commit e1e4313

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎src/oauth/index.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ export class OAuthProviderPublicationError extends Error {
308308
}
309309
}
310310

311+
export class OAuthReauthIdentityMismatchError extends Error {
312+
constructor() {
313+
super("Signed-in account does not match the selected account. Sign in with the same account.");
314+
this.name = "OAuthReauthIdentityMismatchError";
315+
}
316+
}
317+
318+
export class OAuthReauthIdentityUnverifiedError extends Error {
319+
constructor() {
320+
super("Could not verify signed-in account identity for reauth.");
321+
this.name = "OAuthReauthIdentityUnverifiedError";
322+
}
323+
}
324+
311325
/** Project arbitrary OAuth failures onto the small, stable public error vocabulary. */
312326
export function publicOAuthAuthenticationErrorMessage(error: unknown): string {
313327
if (error instanceof OAuthMutationBusyError) {
@@ -318,6 +332,10 @@ export function publicOAuthAuthenticationErrorMessage(error: unknown): string {
318332
if (
319333
(error instanceof OAuthLoginRequiredError && isOAuthProvider(error.provider))
320334
|| error instanceof OAuthProviderPublicationError
335+
// Reauth identity outcomes carry fixed, account-free remediation text. Dropping them to the
336+
// generic message hides WHICH failure the user must fix (sign in with the selected account).
337+
|| error instanceof OAuthReauthIdentityMismatchError
338+
|| error instanceof OAuthReauthIdentityUnverifiedError
321339
|| error instanceof OAuthTokenRefreshBusyError
322340
|| error instanceof OAuthTokenRefreshStaleError
323341
) return error.message;
@@ -1137,15 +1155,15 @@ export async function runLogin(
11371155
const existing = getAccountCredential(provider, opts.reauthAccountId);
11381156
if (!existing) throw new Error(`Unknown account for reauth: ${opts.reauthAccountId}`);
11391157
if (!existing.accountId && !existing.email) {
1140-
throw new Error("Could not verify signed-in account identity for reauth.");
1158+
throw new OAuthReauthIdentityUnverifiedError();
11411159
}
11421160
const identityMatches = existing.accountId && cred.accountId
11431161
? existing.accountId === cred.accountId
11441162
: existing.email && cred.email
11451163
? existing.email.toLowerCase() === cred.email.toLowerCase()
11461164
: false;
11471165
if (!identityMatches) {
1148-
throw new Error("Signed-in account does not match the selected account. Sign in with the same account.");
1166+
throw new OAuthReauthIdentityMismatchError();
11491167
}
11501168
await (deps.saveAccountCredential ?? saveAccountCredential)(provider, opts.reauthAccountId, cred);
11511169
} else {

‎tests/oauth-status-privacy.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
getValidAccessToken,
88
OAuthLoginRequiredError,
99
OAuthProviderPublicationError,
10+
OAuthReauthIdentityMismatchError,
11+
OAuthReauthIdentityUnverifiedError,
1012
OAuthTokenRefreshBusyError,
1113
OAuthTokenRefreshStaleError,
1214
OAUTH_PROVIDERS,
@@ -256,6 +258,12 @@ describe("OAuth status privacy", () => {
256258
expect(publicOAuthAuthenticationErrorMessage(new OAuthProviderPublicationError())).toBe(
257259
"OAuth credential was saved, but the provider entry was not written. Resolve the account namespace collision, then retry login.",
258260
);
261+
expect(publicOAuthAuthenticationErrorMessage(new OAuthReauthIdentityMismatchError())).toBe(
262+
"Signed-in account does not match the selected account. Sign in with the same account.",
263+
);
264+
expect(publicOAuthAuthenticationErrorMessage(new OAuthReauthIdentityUnverifiedError())).toBe(
265+
"Could not verify signed-in account identity for reauth.",
266+
);
259267
expect(publicOAuthAuthenticationErrorMessage(new OAuthTokenRefreshBusyError())).toBe(
260268
"OAuth token refresh capacity reached",
261269
);
@@ -370,6 +378,14 @@ describe("OAuth status privacy", () => {
370378
error: new OAuthLoginRequiredError("xai"),
371379
expected: "Not logged in to xai. Run: ocx login xai",
372380
},
381+
{
382+
error: new OAuthReauthIdentityMismatchError(),
383+
expected: "Signed-in account does not match the selected account. Sign in with the same account.",
384+
},
385+
{
386+
error: new OAuthReauthIdentityUnverifiedError(),
387+
expected: "Could not verify signed-in account identity for reauth.",
388+
},
373389
{
374390
error: new OAuthTokenRefreshBusyError(),
375391
expected: "OAuth token refresh capacity reached",

0 commit comments

Comments
 (0)