@ultimat3/auth 31.34.0 → 31.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/auth",
3
- "version": "31.34.0",
3
+ "version": "31.36.0",
4
4
  "description": "Sessions, passwords, OAuth, MFA and api keys — resolved to one Actor",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -50,8 +50,8 @@
50
50
  "test": "bun test"
51
51
  },
52
52
  "dependencies": {
53
- "@ultimat3/core": "31.34.0",
54
- "@ultimat3/db": "31.34.0",
55
- "@ultimat3/schema": "31.34.0"
53
+ "@ultimat3/core": "31.36.0",
54
+ "@ultimat3/db": "31.36.0",
55
+ "@ultimat3/schema": "31.36.0"
56
56
  }
57
57
  }
package/src/errors.ts CHANGED
@@ -155,7 +155,7 @@ export const authUnauthenticated = (surface: string): AuthError =>
155
155
  new AuthError({
156
156
  code: 'X_UNAUTHENTICATED',
157
157
  cause: `${surface} needs an actor but ctx.actor is anonymous`,
158
- fix: 'send the __Host-x_session cookie with this request, and resolve it once at the boundary: authenticate(auth, readSessionCookie(request, auth.sessions.policy))',
158
+ fix: 'authenticate(auth, readSessionCookie(request, auth.sessions.policy)) // once, at the boundary — and send the __Host-x_session cookie with this request',
159
159
  });
160
160
 
161
161
  export const authForbidden = (surface: string, reason: string): AuthError =>
@@ -171,7 +171,7 @@ export const sessionExpired = (kind: 'absolute' | 'idle', sessionId: string): Au
171
171
  new AuthError({
172
172
  code: 'X_SESSION_EXPIRED',
173
173
  cause: `session ${sessionId} passed its ${kind} expiry`,
174
- fix: `sign in again, or raise session.${kind}TtlMs in defineAuth({ session })`,
174
+ fix: `defineAuth({ session: { ${kind}TtlMs: <ms> } }) // a longer ${kind} window — or sign in again`,
175
175
  });
176
176
 
177
177
  export const sessionUnknown = (): AuthError =>
@@ -181,7 +181,7 @@ export const sessionUnknown = (): AuthError =>
181
181
  // No lookup by cookie is offered, and that is deliberate: a forged id and a deleted session
182
182
  // are indistinguishable here by design. The reader signs in again; a developer holding a
183
183
  // user id can see what is still live without the cookie telling them anything.
184
- fix: 'sign in again to mint a fresh session — listDevices(auth.sessions, userId) lists the sessions still live for a user',
184
+ fix: 'listDevices(auth.sessions, userId) // the sessions still live for a user — sign in again to mint a fresh one',
185
185
  });
186
186
 
187
187
  /**
@@ -193,7 +193,7 @@ export const kdfOverloaded = (active: number, queued: number): AuthError =>
193
193
  new AuthError({
194
194
  code: 'X_OVERLOADED',
195
195
  cause: `${active} password hashes are already running and ${queued} more are queued`,
196
- fix: 'retry after the Retry-After header; widen the ceiling with installKdfGate({ maxConcurrent, maxQueued }) from @ultimat3/auth/adapter, in apps/web/runtime.ts, only if the box has the memory — every argon2id hash holds ~19 MiB while it runs',
196
+ fix: 'installKdfGate({ maxConcurrent, maxQueued }) // from @ultimat3/auth/adapter, in apps/web/runtime.ts, only if the box has the memory — every argon2id hash holds ~19 MiB while it runs; otherwise retry after the Retry-After header',
197
197
  meta: { active, queued, retryAfterSeconds: 1 },
198
198
  });
199
199
 
@@ -211,7 +211,7 @@ export const mfaRequired = (challenge: string): AuthError =>
211
211
  new AuthError({
212
212
  code: 'X_MFA_REQUIRED',
213
213
  cause: 'this account has TOTP enrolled and the second factor has not been satisfied',
214
- fix: 'catch X_MFA_REQUIRED in your sign-in handler, hand error.meta.challenge to the caller, and finish with: await completeMfa(auth, challenge, code)',
214
+ fix: 'await completeMfa(auth, challenge, code) // catch X_MFA_REQUIRED in your sign-in handler, hand error.meta.challenge to the caller, and finish with this',
215
215
  meta: { challenge },
216
216
  });
217
217
 
@@ -224,7 +224,7 @@ export const mfaChallengeInvalid = (): AuthError =>
224
224
  new AuthError({
225
225
  code: 'X_UNAUTHENTICATED',
226
226
  cause: 'the second-factor challenge is not one this app issued, or it is no longer usable',
227
- fix: 'sign in again for a fresh challenge: await login(auth, { email, password })',
227
+ fix: 'await login(auth, { email, password }) // sign in again for a fresh challenge',
228
228
  });
229
229
 
230
230
  /** A wrong or already-spent code. The attempt it cost stays counted against the account. */
@@ -232,7 +232,7 @@ export const mfaCodeRejected = (): AuthError =>
232
232
  new AuthError({
233
233
  code: 'X_UNAUTHENTICATED',
234
234
  cause: 'the second-factor code did not match, or it was already used',
235
- fix: 'read the current code from the authenticator app and retry: await completeMfa(auth, challenge, code)',
235
+ fix: 'await completeMfa(auth, challenge, code) // retry with the current code from the authenticator app',
236
236
  });
237
237
 
238
238
  /**
@@ -252,7 +252,7 @@ export const mfaSecretInvalid = (surface: string): AuthError =>
252
252
  new AuthError({
253
253
  code: 'X_MFA_SECRET_INVALID',
254
254
  cause: `${surface} was given a totp secret that is not RFC 4648 base32, so it decodes to zero bytes`,
255
- fix: 'issue a fresh one and store it: const { secret } = enrolTotp(auth, { account: user.email }) — an imported secret must be base32 (A-Z and 2-7, padding, spaces and dashes ignored) and decode to at least one byte',
255
+ fix: 'const { secret } = enrolTotp(auth, { account: user.email }) // issue a fresh one and store it — an imported secret must be base32 (A-Z and 2-7, padding, spaces and dashes ignored) and decode to at least one byte',
256
256
  });
257
257
 
258
258
  /**
@@ -300,7 +300,7 @@ export const mfaRequiredUnenforceable = (): AuthError =>
300
300
  code: 'X_CONFIG_INVALID',
301
301
  cause:
302
302
  'defineAuth({ mfa: { required: true } }) declares a second factor this package does not enforce: login() mints a full session for any user whose mfaSecret is null',
303
- fix: 'drop required from defineAuth({ mfa }) and gate it in your own sign-in handler, which is where the enrolment route lives: if (user.mfaSecret === null) send them to enrolTotp(auth, { account: user.email }) instead of createSession(auth.sessions, ...)',
303
+ fix: 'defineAuth({ mfa: { issuer } }) // drop required, and gate it in your own sign-in handler, where the enrolment route lives: if (user.mfaSecret === null) send them to enrolTotp(auth, { account: user.email }) instead of createSession(auth.sessions, ...)',
304
304
  });
305
305
 
306
306
  /**
@@ -349,7 +349,7 @@ export const authPolicyNumberInvalid = (
349
349
  new AuthError({
350
350
  code: 'X_CONFIG_INVALID',
351
351
  cause: `defineAuth({ ${key}: ${String(value)} }) is not ${expected}; ${consequence}, so the rule is not enforced at all rather than enforced wrongly — and NaN is what Number(process.env.…) answers for an unset variable`,
352
- fix: `pass ${expected} for ${key} in defineAuth, and parse an environment value before you pass it — Number.parseInt(process.env.AUTH_TTL_MS ?? '', 10) is NaN when the variable is unset, so give it a default: Number.parseInt(process.env.AUTH_TTL_MS ?? '2592000000', 10)`,
352
+ fix: `Number.parseInt(process.env.AUTH_TTL_MS ?? '2592000000', 10) // pass ${expected} for ${key} in defineAuth, and parse an environment value with a default — Number.parseInt(process.env.AUTH_TTL_MS ?? '', 10) is NaN when the variable is unset`,
353
353
  meta: { option: key, value: String(value) },
354
354
  });
355
355
 
@@ -364,7 +364,7 @@ export const apiKeyEnvInvalid = (env: string): AuthError =>
364
364
  cause: env.includes('_')
365
365
  ? `api key env ${renderCauseValue(env)} contains "_", which parseApiKey splits on`
366
366
  : `api key env ${renderCauseValue(env)} is not lowercase letters, digits and "-", the only spelling that survives parseApiKey and reads the same in every log`,
367
- fix: "pass env matching ^[a-z0-9-]+$ to issueApiKey (e.g. 'live-eu')",
367
+ fix: "issueApiKey({ env: 'live-eu', scopes }) // env matches ^[a-z0-9-]+$",
368
368
  meta: { option: 'env' },
369
369
  });
370
370
 
@@ -377,7 +377,7 @@ export const apiKeyScopeWildcard = (scope: string): AuthError =>
377
377
  new AuthError({
378
378
  code: 'X_CONFIG_INVALID',
379
379
  cause: `api key scope ${renderCauseValue(scope)} is a wildcard, and a key carries exactly the permissions it names`,
380
- fix: "pass each permission by name to issueApiKey({ scopes }) — e.g. scopes: ['post:read', 'post:publish']",
380
+ fix: "issueApiKey({ env, scopes: ['post:read', 'post:publish'] }) // each permission by name, never a wildcard",
381
381
  meta: { option: 'scopes' },
382
382
  });
383
383
 
@@ -385,7 +385,7 @@ export const passwordWeak = (reasons: readonly string[]): AuthError =>
385
385
  new AuthError({
386
386
  code: 'X_PASSWORD_WEAK',
387
387
  cause: `password rejected: ${reasons.join('; ')}`,
388
- fix: 'choose a longer, uncommon password — or relax defineAuth({ password: { minLength } })',
388
+ fix: 'defineAuth({ password: { minLength } }) // relax the policy — or choose a longer, uncommon password',
389
389
  });
390
390
 
391
391
  /** The tenant bucket's key prefix. Declared here because the refusal below must recognise it. */
@@ -410,8 +410,8 @@ export const accountLocked = (key: string, retryAfterSeconds: number): AuthError
410
410
  ? `sign-in is locked out for another ${retryAfterSeconds}s after repeated failures`
411
411
  : `${renderCauseValue(key)} is locked out for another ${retryAfterSeconds}s after repeated failures`,
412
412
  fix: tenant
413
- ? `wait ${retryAfterSeconds}s — or clear the one bucket that is holding: await auth.orgLimiter.recordSuccess(orgKey(user.orgId)) — or raise defineAuth({ rateLimit })`
414
- : `wait ${retryAfterSeconds}s — or clear this one bucket: await auth.limiter.recordSuccess(${renderFixLiteral(key, '<key>')}) — or raise defineAuth({ rateLimit })`,
413
+ ? `await auth.orgLimiter.recordSuccess(orgKey(user.orgId)) // clears the one bucket that is holding — or wait ${retryAfterSeconds}s, or raise defineAuth({ rateLimit })`
414
+ : `await auth.limiter.recordSuccess(${renderFixLiteral(key, '<key>')}) // clears this one bucket — or wait ${retryAfterSeconds}s, or raise defineAuth({ rateLimit })`,
415
415
  // `kdfOverloaded`'s shape: `@ultimat3/http`'s `retryAfterOf` reads exactly this field. `key`
416
416
  // stays out — `cause`/`fix` escape it on purpose and `meta` is read by surfaces that do not.
417
417
  meta: { retryAfterSeconds },
@@ -425,7 +425,7 @@ export const apiKeyInvalid = (): AuthError =>
425
425
  cause: 'the presented api key is unknown, revoked, expired or does not match its hash',
426
426
  // Which of the four it was is not named here and never will be — see the factory's contract
427
427
  // above — so the fix is the one action that resolves all four: issue a replacement.
428
- fix: 'issue a replacement: const { plaintext, record } = issueApiKey({ env, scopes }); await auth.adapter.putApiKey(record) — auth.adapter.listApiKeys(ownerId) through describeApiKey() shows which keys are still live',
428
+ fix: 'const { plaintext, record } = issueApiKey({ env, scopes }); await auth.adapter.putApiKey(record) // issue a replacement — auth.adapter.listApiKeys(ownerId) through describeApiKey() shows which keys are still live',
429
429
  });
430
430
 
431
431
  /**
@@ -456,7 +456,7 @@ export const authUniqueViolation = (operation: string, table: string, column: st
456
456
  new AuthError({
457
457
  code: 'X_AUTH_WRITE_FAILED',
458
458
  cause: `${operation} would add a second ${table} row with the same ${column}, which that column's unique constraint refuses`,
459
- fix: `look the row up first and update it — findUserByEmail(normaliseEmail(email)) — or write a different ${column}`,
459
+ fix: `await auth.adapter.findUserByEmail(normaliseEmail(email)) // look the row up first and update it — or write a different ${column}`,
460
460
  meta: { operation, table, column },
461
461
  });
462
462
 
@@ -469,7 +469,7 @@ export const authLimiterNotShared = (found: string): AuthError =>
469
469
  new AuthError({
470
470
  code: 'X_AUTH_LIMITER_NOT_SHARED',
471
471
  cause: `rateLimit.scope is 'shared' but the limiter in use is ${found}, so every replica would grant the full maxAttempts on its own`,
472
- fix: "pass a limiter whose scope is 'shared' — defineAuth({ adapter, limiter }) — or set rateLimit.scope: 'process' in defineAuth to accept per-replica lockouts",
472
+ fix: "defineAuth({ adapter, limiter }) // a limiter whose scope is 'shared' — or set rateLimit.scope: 'process' in defineAuth to accept per-replica lockouts",
473
473
  meta: { scope: found },
474
474
  });
475
475
 
@@ -487,6 +487,6 @@ export const authLimiterPolicyMismatch = (
487
487
  new AuthError({
488
488
  code: 'X_AUTH_LIMITER_POLICY_MISMATCH',
489
489
  cause: `defineAuth declares rateLimit.${field} = ${declared} but the limiter passed to it enforces ${enforced}; if ${enforced} is the number this deployment means to enforce, then the declaration is the half that is wrong`,
490
- fix: `construct the limiter with ${field}: ${declared} — defineAuth({ rateLimit, limiter }) compares the two, and the declaration is what Auth.rateLimit reports`,
490
+ fix: `{ ${field}: ${declared} } // in the policy the limiter is constructed with — defineAuth({ rateLimit, limiter }) compares the two, and the declaration is what Auth.rateLimit reports`,
491
491
  meta: { field, declared, enforced },
492
492
  });
package/src/id-token.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  // what silently makes the second door as trusting as the first.
9
9
 
10
10
  import type { Clock } from '@ultimat3/core';
11
- import { renderCauseValue, timingSafeEqual } from '@ultimat3/core';
11
+ import { renderCauseValue, renderFixShellArg, timingSafeEqual } from '@ultimat3/core';
12
12
  import { decodeJwtSegment } from './json';
13
13
  import { type IdTokenKeys, verifyJwtSignature } from './jwks';
14
14
  import type { OAuthProvider, OAuthProviderId } from './oauth';
@@ -175,7 +175,7 @@ export async function verifyIdToken(input: VerifyIdTokenInput): Promise<IdTokenC
175
175
  throw oauthTokenInvalid(
176
176
  provider.id,
177
177
  'aud does not include the client id this handshake was started with',
178
- `set ${provider.clientIdEnv} to the same client id beginOAuth() was called with`,
178
+ `export ${renderFixShellArg(provider.clientIdEnv, '<CLIENT_ID_ENV>')}=<client id> # the same client id beginOAuth() was called with`,
179
179
  );
180
180
  }
181
181
 
@@ -195,7 +195,7 @@ export async function verifyIdToken(input: VerifyIdTokenInput): Promise<IdTokenC
195
195
  throw oauthTokenInvalid(
196
196
  provider.id,
197
197
  'the token is already expired',
198
- `sync this host's clock (\`timedatectl status\`), then ${restartAt(provider.id)}`,
198
+ `timedatectl status # sync this host's clock, then ${restartAt(provider.id)}`,
199
199
  );
200
200
  }
201
201
 
@@ -206,7 +206,7 @@ export async function verifyIdToken(input: VerifyIdTokenInput): Promise<IdTokenC
206
206
  throw oauthTokenInvalid(
207
207
  provider.id,
208
208
  'the token is not valid yet',
209
- `sync this host's clock (\`timedatectl status\`), then ${restartAt(provider.id)}`,
209
+ `timedatectl status # sync this host's clock, then ${restartAt(provider.id)}`,
210
210
  );
211
211
  }
212
212
 
package/src/jwks.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  isFixShellSafe,
14
14
  liveClock,
15
15
  logger,
16
+ renderFixLiteral,
16
17
  renderFixShellArg,
17
18
  renderThrowable,
18
19
  singleFlight,
@@ -376,7 +377,7 @@ export function providerJwks(
376
377
  throw oauthTokenInvalid(
377
378
  provider.id,
378
379
  'this provider publishes no jwks_uri, so an id token from it can only be trusted on the token endpoint',
379
- `register ${provider.id} with an explicit jwksUri, or read its id token only through exchangeOAuthCode()`,
380
+ `registerOAuthProvider({ id: ${renderFixLiteral(provider.id, "'<id>'")}, jwksUri: '<the provider jwks_uri>', ... }) // or read its id token only through exchangeOAuthCode()`,
380
381
  );
381
382
  }
382
383
  const bespoke = options !== undefined && Object.keys(options).length > 0;
@@ -128,7 +128,7 @@ export async function discoverOAuthProvider(
128
128
  provider: input.id,
129
129
  stage: 'discovery',
130
130
  detail: 'the discovery document is not a JSON object',
131
- fix: `confirm ${target} is the OP's own discovery document and not a login page`,
131
+ fix: `curl -sS -m 5 -i ${target} # the OP's own discovery document is JSON; a login page means the issuer is wrong — pass the real one to discoverOAuthProvider({ issuer })`,
132
132
  });
133
133
  }
134
134
 
@@ -169,7 +169,7 @@ export async function discoverOAuthProvider(
169
169
  // `renderFixLiteral` and not the shell renderer: this fix is a JS call, where quoting IS
170
170
  // the escape. A bare interpolation inside the single quotes it used to carry meant an id
171
171
  // holding an apostrophe closed the literal and printed a fix that does not parse.
172
- fix: `register this provider by hand with an explicit jwksUri: registerOAuthProvider({ id: ${renderFixLiteral(input.id, "'<id>'")}, ... })`,
172
+ fix: `registerOAuthProvider({ id: ${renderFixLiteral(input.id, "'<id>'")}, jwksUri: '<the provider jwks_uri>', ... }) // register this provider by hand, with an explicit jwksUri`,
173
173
  });
174
174
  }
175
175
 
@@ -9,6 +9,7 @@ import {
9
9
  liveClock,
10
10
  logger,
11
11
  renderCauseValue,
12
+ renderFixLiteral,
12
13
  renderFixShellArg,
13
14
  renderThrowable,
14
15
  } from '@ultimat3/core';
@@ -96,7 +97,7 @@ export function oauthCredentials(
96
97
  if (missing.length > 0) {
97
98
  throw new EnvMissingError({
98
99
  cause: `${provider} oauth is enabled but ${missing.join(' and ')} ${missing.length === 1 ? 'is' : 'are'} not set`,
99
- fix: `add ${missing.join(' and ')} to .env from the ${provider} app's credentials, then run: x doctor --json`,
100
+ fix: `export ${renderFixShellArg(missing[0], '<KEY>')}=<value> # each of ${missing.join(' and ')}, from the ${provider} app's credentials, in .env or the deployed environment — then x doctor --json`,
100
101
  meta: { provider, missing },
101
102
  });
102
103
  }
@@ -273,7 +274,7 @@ async function postForm(
273
274
  provider,
274
275
  stage: 'token',
275
276
  detail: 'the token endpoint answered 200 with a body that is not a JSON object',
276
- fix: `confirm ${url} is the provider's real token endpoint and not a proxy`,
277
+ fix: `curl -sS -m 5 -X POST ${renderFixShellArg(url, '<the provider token endpoint>')} # a real token endpoint answers a JSON error object; HTML or a redirect means a proxy or a login page`,
277
278
  });
278
279
  }
279
280
 
@@ -353,7 +354,7 @@ export async function exchangeOAuthCode(
353
354
  provider: provider.id,
354
355
  stage: 'token',
355
356
  detail: 'the response carried no access_token',
356
- fix: `confirm the ${provider.id} app grants the scopes in providerFor('${provider.id}').scopes`,
357
+ fix: `providerFor(${renderFixLiteral(provider.id, "'<id>'")}).scopes // the scopes the ${provider.id} app must grant`,
357
358
  });
358
359
  }
359
360
 
@@ -369,7 +370,7 @@ export async function exchangeOAuthCode(
369
370
  provider: provider.id,
370
371
  stage: 'token',
371
372
  detail: 'the response carried no id_token',
372
- fix: `include "openid" in the scopes passed to beginOAuth() for ${provider.id}`,
373
+ fix: `beginOAuth({ provider: ${renderFixLiteral(provider.id, "'<id>'")}, clientId, redirectUri, scopes: ['openid', ...providerFor(${renderFixLiteral(provider.id, "'<id>'")}).scopes] }) // an OIDC provider answers an id_token only for openid`,
373
374
  });
374
375
  }
375
376
 
@@ -3,7 +3,7 @@
3
3
  // matter which door the user came through. `completeOAuthLogin` is the blessed entry point;
4
4
  // the three steps under it are exported because a custom flow needs the seams, not a second path.
5
5
 
6
- import { ConfigInvalidError, logger, uuidV7 } from '@ultimat3/core';
6
+ import { ConfigInvalidError, logger, renderFixLiteral, uuidV7 } from '@ultimat3/core';
7
7
  import type { AuthAccount, AuthUser } from './adapter';
8
8
  import type { Auth, LoginResult } from './auth';
9
9
  import { normaliseEmail } from './email';
@@ -37,7 +37,7 @@ export const oauthAccountNotLinked = (provider: string, email: string): AuthErro
37
37
  new AuthError({
38
38
  code: 'X_UNAUTHENTICATED',
39
39
  cause: `an account holds this ${provider} address but never verified it, so ${provider} may not claim it`,
40
- fix: `sign in with that account's password and confirm the email-verify link, then retry ${provider}`,
40
+ fix: `await login(auth, { email, password }) // sign in with that account's password and confirm the email-verify link, then retry ${provider}`,
41
41
  meta: { provider, email },
42
42
  });
43
43
 
@@ -50,7 +50,7 @@ export const oauthLinkingDisabled = (provider: string, email: string): AuthError
50
50
  new AuthError({
51
51
  code: 'X_UNAUTHENTICATED',
52
52
  cause: `an account already holds this address and defineAuth({ link: 'never' }) forbids ${provider} from claiming it`,
53
- fix: "sign in with that account's own credentials, or set link: 'verified-email' in defineAuth to let a provider-verified address claim a locally-verified account",
53
+ fix: "defineAuth({ adapter, link: 'verified-email' }) // lets a provider-verified address claim a locally-verified account — or sign in with that account's own credentials",
54
54
  meta: { provider, email },
55
55
  });
56
56
 
@@ -67,7 +67,7 @@ export const emailVerifiedNotStored = (provider: string, userId: string): AuthEr
67
67
  // implements `updateUser` and lost a write it accepted.
68
68
  code: 'X_AUTH_WRITE_FAILED',
69
69
  cause: `the adapter returned no row for new user ${userId}, so the ${provider}-verified address was never stamped verified`,
70
- fix: 'return the updated row from AuthAdapter.updateUser — MemoryAuthAdapter.updateUser is the reference implementation',
70
+ fix: "grep -n -A16 'async updateUser' node_modules/@ultimat3/auth/src/memory-adapter.ts # the reference implementation: AuthAdapter.updateUser returns the updated row",
71
71
  meta: { provider, userId },
72
72
  });
73
73
 
@@ -172,7 +172,7 @@ async function createUserFor(auth: Auth, input: OAuthSignInInput): Promise<AuthU
172
172
  provider: input.profile.provider,
173
173
  stage: 'userinfo',
174
174
  detail: 'the provider returned an identity with no email address',
175
- fix: `request the email scope for ${input.profile.provider} in beginOAuth(), then ${restartAt(input.profile.provider)}`,
175
+ fix: `beginOAuth({ provider: ${renderFixLiteral(input.profile.provider, "'<id>'")}, clientId, redirectUri, scopes: ['email', ...providerFor(${renderFixLiteral(input.profile.provider, "'<id>'")}).scopes] }) // request the email scope, then ${restartAt(input.profile.provider)}`,
176
176
  });
177
177
  }
178
178
  // The provider did not vouch for the address, so this caller has proven nothing about owning
@@ -282,7 +282,7 @@ export async function signInWithOAuth(auth: Auth, input: OAuthSignInInput): Prom
282
282
  if (!auth.providers.includes(provider)) {
283
283
  throw new ConfigInvalidError({
284
284
  cause: `${provider} is not in defineAuth({ providers }), so a ${provider} identity cannot sign in`,
285
- fix: `add '${provider}' to defineAuth({ providers: [...] }), or stop offering the ${provider} button`,
285
+ fix: `defineAuth({ adapter, providers: [${renderFixLiteral(provider, "'<id>'")}] }) // beside the ids already there — or stop offering the ${provider} button`,
286
286
  meta: { provider, enabled: [...auth.providers] },
287
287
  });
288
288
  }
@@ -3,7 +3,7 @@
3
3
  // when there is not. `emailVerified` is carried honestly rather than assumed — it is what
4
4
  // decides whether this login may attach itself to an existing account by address.
5
5
 
6
- import { logger, renderFixShellArg, renderThrowable } from '@ultimat3/core';
6
+ import { logger, renderFixLiteral, renderFixShellArg, renderThrowable } from '@ultimat3/core';
7
7
  import { outboundResponse } from '@ultimat3/core/outbound';
8
8
  import { idTokenEmailVerified, isVerifiedFlag } from './id-token';
9
9
  import { isRecord } from './json';
@@ -161,7 +161,7 @@ export async function userinfoBody(
161
161
  provider,
162
162
  stage: 'userinfo',
163
163
  detail: `${provider} publishes no userinfo endpoint and its id token carried no identity`,
164
- fix: `request the "email" scope for ${provider} in beginOAuth(), then ${restartAt(provider)}`,
164
+ fix: `beginOAuth({ provider: ${renderFixLiteral(provider, "'<id>'")}, clientId, redirectUri, scopes: ['email', ...providerFor(${renderFixLiteral(provider, "'<id>'")}).scopes] }) // request the email scope, then ${restartAt(provider)}`,
165
165
  });
166
166
  }
167
167
 
@@ -172,7 +172,7 @@ export async function userinfoBody(
172
172
  stage: 'userinfo',
173
173
  detail: result.detail,
174
174
  status: result.status,
175
- fix: `confirm the ${provider} app still grants ${config.scopes.join(' ')}, then ${restartAt(provider)}`,
175
+ fix: `providerFor(${renderFixLiteral(provider, "'<id>'")}).scopes // confirm the ${provider} app still grants each one, then ${restartAt(provider)}`,
176
176
  });
177
177
  }
178
178
  if (!isRecord(result.body)) {
@@ -180,7 +180,7 @@ export async function userinfoBody(
180
180
  provider,
181
181
  stage: 'userinfo',
182
182
  detail: 'the userinfo endpoint answered 200 with a body that is not a JSON object',
183
- fix: `confirm ${url} is the provider's real userinfo endpoint and not a proxy`,
183
+ fix: `curl -sS -m 5 -H 'authorization: Bearer <access token>' ${renderFixShellArg(url, '<the provider userinfo endpoint>')} # the real userinfo endpoint answers a JSON object; HTML means a proxy or a login page`,
184
184
  });
185
185
  }
186
186
  return result.body;
@@ -212,7 +212,7 @@ async function fromUserInfo(
212
212
  provider,
213
213
  stage: 'userinfo',
214
214
  detail: 'the profile carried no stable account id',
215
- fix: `confirm the ${provider} app requests ${config.scopes.join(' ')}, then ${restartAt(provider)}`,
215
+ fix: `providerFor(${renderFixLiteral(provider, "'<id>'")}).scopes // confirm the ${provider} app requests each one, then ${restartAt(provider)}`,
216
216
  });
217
217
  }
218
218
 
@@ -274,7 +274,7 @@ export async function readOAuthProfile(
274
274
  provider,
275
275
  stage: 'userinfo',
276
276
  detail: 'the userinfo subject is not the subject of the verified id token',
277
- fix: `confirm ${userInfoUrl} is ${provider}'s own userinfo endpoint and not a proxy that rewrites sub`,
277
+ fix: `curl -sS -m 5 -H 'authorization: Bearer <access token>' ${renderFixShellArg(userInfoUrl, '<the provider userinfo endpoint>')} | jq .sub # must equal the id token's sub — a different one means a proxy rewrites it`,
278
278
  });
279
279
  }
280
280
  return read;
@@ -21,7 +21,7 @@ export const oauthProviderDuplicate = (provider: string): AuthError =>
21
21
  new AuthError({
22
22
  code: 'X_OAUTH_PROVIDER_DUPLICATE',
23
23
  cause: `an oauth provider is already registered as ${renderCauseValue(provider)}, so the second registration would silently replace the first`,
24
- fix: `give one of them a different id, or delete the duplicate registerOAuthProvider({ id: ${renderFixLiteral(provider, '<id>')} }) call`,
24
+ fix: `grep -rn registerOAuthProvider apps packages # give one of the two calls claiming ${renderFixLiteral(provider, '<id>')} a different id, or delete the duplicate — github and google are registered by @ultimat3/auth itself`,
25
25
  meta: { provider },
26
26
  });
27
27
 
@@ -123,7 +123,7 @@ function uncoded(error: unknown): UltimateError {
123
123
  detail:
124
124
  'an adapter or fetch this package does not own threw a value with no error code; the ' +
125
125
  'detail is in this process log under auth.oauth.uncoded_failure',
126
- fix: 'throw an UltimateError from the AuthAdapter or OAuthFetch that failed — the factories are in packages/auth/src/errors.ts, and the OAuth ones in packages/auth/src/oauth-errors.ts',
126
+ fix: "authWriteFailed('updateUser', 'x_users') // throw an UltimateError like this one from the AuthAdapter or OAuthFetch that failed — the factories are in packages/auth/src/errors.ts, and the OAuth ones in packages/auth/src/oauth-errors.ts",
127
127
  });
128
128
  }
129
129
 
package/src/verify.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // tier 4 and auth is tier 2, so the app wires mail's `send` in and auth imports nothing upward.
5
5
 
6
6
  import type { Clock } from '@ultimat3/core';
7
- import { timingSafeEqual } from '@ultimat3/core';
7
+ import { renderFixLiteral, timingSafeEqual } from '@ultimat3/core';
8
8
  import type { AuthVerification, VerificationStore } from './adapter';
9
9
  import { normaliseEmail } from './email';
10
10
  import { AuthError } from './errors';
@@ -128,7 +128,7 @@ const verificationInvalid = (purpose: string): AuthError =>
128
128
  new AuthError({
129
129
  code: 'X_UNAUTHENTICATED',
130
130
  cause: `the ${purpose} token is unknown, already used, expired or does not match`,
131
- fix: `request a new link — ${purpose} tokens are single-use`,
131
+ fix: `await issueVerification(runtime, { purpose: ${renderFixLiteral(purpose, "'<purpose>'")}, identifier: email, locale }) // a new link — ${purpose} tokens are single-use`,
132
132
  });
133
133
 
134
134
  export interface ConsumeVerificationInput {
package/src/workload.ts CHANGED
@@ -77,7 +77,7 @@ const refused = (reason: string): AuthError =>
77
77
  cause: `the presented workload token was refused: ${reason}`,
78
78
  // A service credential names no human, so a precise cause enumerates nothing — and the
79
79
  // reader of this line is an operator holding a misconfigured deployment, not an attacker.
80
- fix: "confirm the workload token's issuer, audience and key set match verifyWorkloadToken({ issuers, audience, keys })",
80
+ fix: "verifyWorkloadToken({ token, issuers, audience, keys, clock }) // the issuer, audience and key set this service passes must match the workload token's",
81
81
  });
82
82
 
83
83
  const readScopes = (payload: Record<string, unknown>): readonly string[] => {