Skip to content

Commit 4c0cf65

Browse files
feat(plugin-auth): the environment-access refusal carries the host's reason and sentence (#34265)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSUQWB2j9eHYsRcrCiq1X1C)_ ## 维护者速读 - 改了什么:云端拒绝某账号进入环境时,宿主可以说明原因(「不是该组织成员」「邀请尚未接受」)和一句给用户看的话;这个原因经环境自己的登录回调一路带到环境登录页,登录页按原因显示对应的本地化句子。应用把用户送来登录时,登录页显示「登录以继续前往 应用名」,而不再只显示对方的域名。 - 为什么改:cloud#4471 的托管登录需要告诉用户为什么进不去、该怎么做,也需要让用户知道自己正在登录哪个应用。 - 风险与回滚:宿主仍返回 true/false 时,三种拒绝回复与改动前逐字节一致(有测试钉住),谁能进入没有任何变化。新增一个无需登录的只读接口,只回答应用名,而且只回答已签名请求里点名的那个应用,其余情况一律同一个 404,并按来源地址限流(每 60 秒 10 次)。回滚即还原本 PR;云端只有在用上本版本 plugin-auth 之后才能返回原因对象。 - 先看:`packages/plugins/plugin-auth/src/oauth-client-name.ts`(新接口的放行条件)、`oauth-callback-refusal-reason.ts`(回调上带原因的条件)、`ui/apps/console/src/pages/auth/LoginPage.tsx`(登录页的两处读取)。 - 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/oauth-authorize-refusal.test.ts`,预期 69 个测试全部通过。 - 需要你做的:无,席位落地。 Fixes #34168 Clause-②: yes (widening) Metadata-protocol: none ## What changes All four items of the card. - **The seam may say why (item 1).** `AuthManagerOptions.oidcAuthorizeGate` may answer `OidcAuthorizeGateRefusal` (`{ allowed: false, reason, message }`) in place of `false`. An object refuses only when it says `allowed: false`; every other answer keeps the truthiness the gate was always read with, so nothing changes who is admitted. - **The refusal carries it (item 2)**, on each door `oauth-authorize-refusal.ts` already chooses between: - the `403` envelope keeps `code: ENV_ACCESS_DENIED`, gains `reason`, and its `message` is the host's sentence; - the redirect back to a registered `redirect_uri` keeps `error=access_denied` (RFC 6749 §4.1.2.1), sends the host's sentence as `error_description`, and adds `objectstack_error_reason`; - the readable page shows the host's sentence, HTML-escaped, after the signed-in account. - **Nothing the host answers is trusted.** A reason outside `[a-z_]{1,40}` is dropped and the refusal stands. A sentence with a control character or an angle bracket, or longer than 300 characters, is replaced by the fixed sentence. On the redirect only, a sentence outside the character set RFC 6749 §4.1.2.1 allows for `error_description` (printable ASCII without the double quote and the backslash) is also replaced by the fixed sentence. - **Why `objectstack_error_reason`.** RFC 6749 §8.2 asks an extension parameter that is not registered to carry a vendor prefix, so it cannot collide with a registered name. The card's example, `error_reason`, is not free: some identity providers already send it with their own values. - **The reason reaches the environment's sign-in page (item 3).** The environment's OAuth callback (`GET /callback/:id`) rebuilds its error redirect from `error` and `error_description` only. One after-hook, `carryRefusalReasonOnCallback` (`oauth-callback-refusal-reason.ts`, called from `auth-manager-after-hook.ts`), puts the reason back on that redirect. It acts only when all of these hold: a `GET` of the platform identity provider's callback; the request's own query says `error=access_denied` and carries exactly one reason of the validated shape; the callback answered a redirect whose query says `error=access_denied` and carries no reason yet. The rest of the location is kept byte for byte. The organization's name is not a field anywhere: it travels only inside the host's sentence. - **The Console's sentences (item 3).** `ssoCallbackRefusalMessage` takes the reason: `not_member` and `invitation_pending` get their own sentences, under `access_denied` only. An unknown reason, no reason, or a reason beside another error code keeps today's sentence. Three keys are added in all eleven packs (real translations; zh-Hant regenerated by `gen:zh-hant`): `auth.login.errors.ssoAccessDeniedNotMember`, `auth.login.errors.ssoAccessDeniedInvitationPending`, `auth.login.ssoHandoffClient`. - **The application's name on a hand-off (item 4).** The sign-in page reads the client name only for the client its signed request names. New route `GET /api/v1/auth/oauth2/client-name?client_id=CLIENT_ID&oauth_query=SIGNED_QUERY` (`oauth-client-name.ts`, mounted in `auth-plugin.ts`, ledgered in `auth-route-ledger.ts` as `public`): - `oauth_query` must carry a signature this server made and that has not expired, checked by the provider's own `verifyOAuthQueryParams`; the session is never read; - the client is the single `client_id` inside the verified request, and the URL's `client_id` must equal it; - the answer is `{ client_name }` and nothing else of the client; - a signature that does not verify or has expired, a mismatched `client_id`, an unknown client, a disabled client and a client with no name all answer the same `404`; a parameter outside the closed set, a repeated one or a missing one answers `400`; - it is rate-limited per client address (ADR-0121 D6), counted before anything is read; over the limit it answers `429` `RATE_LIMIT_EXCEEDED` with `Retry-After`. `LoginPage` asks it once on a signed hand-off and shows "Sign in to continue to NAME"; any other answer (refusal, network failure, another body shape, no signed request on the URL) keeps "Continue to HOST". - **The registered-`redirect_uri` rule is unchanged**: the redirect is followed exactly when it was before. ## Tests - `packages/plugins/plugin-auth/src/oauth-authorize-refusal.test.ts`, over the file's real-`AuthManager` harness (real better-auth, the real oauth-provider): - items 1 and 2 as in round 1: the boolean CONTROL (envelope body, redirect parameters in order, page SHA-256 equal to the merge base's), reason and sentence pins on each door, the admitted set unchanged, the resume pass; - the client-name read: the matched client is served exactly `{ success: true, data: { client_name } }`; a mismatched `client_id` is refused and the other client's name never appears; an unknown client, a disabled client, a signed request whose `client_id` was changed, and an expired one each get the same refusal as a mismatch; three malformed requests answer `400`; the window's reads from one address answer, the next is refused with `429`, `RATE_LIMIT_EXCEEDED`, `Retry-After` and `no-store`, and another address still answers; - the callback carry: an environment `AuthManager` with the platform identity provider and a second one, fed the provider's real refusal parameters. The reason lands on `/_console/login` beside `error` and `error_description`; CONTROL: a boolean refusal lands with no reason; not carried for a reason of another shape, a reason beside another error, a reason from the other identity provider, or two reasons. - `auth-route-ledger.conformance.test.ts`: the new route in the objectstack list. - Console: `LoginPage.access-denied-32992.test.tsx` gains a describe for the two reasons, an unknown reason and a reason beside another code. New `LoginPage.handoff-client-name-34168.test.tsx`: the name is shown and asked with the URL's client and the whole signed request; the host line stays on a 404, a network failure and a body of another shape; CONTROL: no signed request, nothing asked. <details><summary>Ablations (each mutation landed on disk through scripts/ablation-replace.mjs; every restore read blob == HEAD and git diff HEAD empty; the subjects resolve from src, no build between legs)</summary> | Ablation (round 2, at `fb0d4b052`) | Result | |:--|:--| | client-name: URL `client_id` no longer has to equal the signed one | 1 failed (the mismatch pin) | | client-name: disabled check removed | 1 failed (disabled) | | client-name: signature verification removed | 1 failed (expired) | | callback: platform-provider check removed | 1 failed (other identity provider) | | callback: reason shape check removed | 1 failed (reason of another shape) | | callback: exactly-one-reason check loosened | 1 failed (two reasons) | | callback: both `access_denied` checks removed (request held, redirect ablated) | 1 failed (reason beside another error) | | Console: reason read under any error code | 1 failed (reason beside another code) | | Console: client-name body shape loosened | 1 failed (body of another shape) | | client-name: rate limit removed (round 3, at `749c7a2ca`) | 1 failed (the rate-limit pin: expected 200 to be 429) | Round 1 (items 1 and 2) ablations stand as reported there: reason pattern 6 failed, sentence markup 2, sentence length 1, RFC charset 1, object truthiness 1, page escape 1. </details> ## Acceptance notes - A host may return the refusal object only once it runs this plugin-auth release or later: an older plugin-auth reads any object as truthy, which admits. The changeset says so. - The new route is rate-limited per client address: a fixed window of 10 reads per 60 seconds, counted before anything is read, in the kernel `cache` service when one is registered, as the signed-out invitation preview is (ADR-0121 D6). Over the limit it answers `429` `RATE_LIMIT_EXCEEDED` with `Retry-After` and `Cache-Control: no-store`. - The new route is an unauthenticated door, which ADR-0138 D2 asks to be recorded in an ADR amendment; `docs/adr/**` is outside this card's file surface, so that note is left to the seat. - The callback carry covers the `GET` callback. A provider that answers by `form_post` reaches `POST /callback/:id`, which the vendor re-issues as a `GET` rebuilt from its own known fields, so the reason would not survive that hop. The platform identity provider answers by query redirect, so this path is not exercised today. - The new types (`OidcAuthorizeGateRefusal` and the rest) are exported from their modules, not re-exported from the package index. - No `packages/spec/src/**` file is touched. ## Verification Round 3 (`749c7a2ca`) adds the rate limit and touches plugin-auth only, so the plugin-auth suite and typecheck were re-read there; the Console, i18n and derived-gate readings below are from `fb0d4b052`, whose `ui/` tree is unchanged at `749c7a2ca`. <details><summary>plugin-auth suite and typecheck</summary> - After `pnpm --filter '@objectstack/plugin-auth^...' build` and the package's own build, under `os-verify-lock`: `pnpm --filter @objectstack/plugin-auth test` exit 0, Test Files 278 passed (278), Tests 5668 passed, 10 skipped. - `pnpm --filter @objectstack/plugin-auth typecheck` exit 0: all three legs (`tsc --noEmit`, `tsconfig.examples.json`, `check:test-typecheck`: "OK — @objectstack/plugin-auth's test layer compiles"). - At `fb0d4b052` the full workspace build (119 tasks) and `pnpm check:dual-build-cjs-loads` were green; round 3 adds no export and no new file. </details> <details><summary>Console and i18n</summary> From `ui/`: `pnpm exec vitest run` over `apps/console/src/pages/auth/`, `all-locales-key-parity`, `untranslated-identity-4376`, `en-zh-key-parity` and the product-neutral ratchet: Test Files 39 passed (39), Tests 429 passed (429). `turbo run type-check --filter=@object-ui/console`: exit 0, 75 tasks successful. `node scripts/check-i18n-en-drift.mjs`: exit 0, "No en value changed in this range." </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `fb0d4b052`: 83 families, each run with stdin closed after the full build, reconciled with `--ran` (83 derived, 83 run). 82 exit 0, among them `pnpm check:auth-mount-ledger` and `pnpm check:dual-build-cjs-loads` ("123 published require entry point(s) across 72 package(s) load"). 1 NOT MEASURED: `pnpm check:type-check-debt` exit 3 (PREREQUISITE NOT MET: its own closure build did not get a turn on the shared verify lock), and two further locked tries timed out in the queue (exit 99); read from CI. PR-body gate: `check-closing-keyword-parity --body` on this body binds only `Fixes #34168`. </details> <details><summary>Merge-tree (throwaway bare clone, no merge driver)</summary> `git merge-tree --write-tree` of `749c7a2ca` against `origin/main` (`951eceeee`): exit 0, no conflicted path. #34257 has no pushed branch, so there is nothing to probe against. </details> <details><summary>Clause-② re-measured</summary> `yes (widening)` holds: the gate option's return type widens, the envelope gains an optional `reason`, the redirects gain an optional parameter, one public, rate-limited read route is added, and three i18n keys are added. Nothing narrows: a boolean answer is byte-identical, and every existing route answers as before. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8436f67 commit 4c0cf65

27 files changed

Lines changed: 1357 additions & 29 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@object-ui/console': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat(plugin-auth): the environment-access refusal can carry the host's reason and sentence to the sign-in page, and the sign-in page names the application on a hand-off
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
`AuthManagerOptions.oidcAuthorizeGate` (the ADR-0069 D5.1 environment-access gate) may now answer `{ allowed: false, reason, message }` in place of `false`: a reason code from the host's own closed set and the sentence the refused person reads. The refusal then carries both:
13+
14+
- the `403` envelope keeps `code: ENV_ACCESS_DENIED`, gains `reason`, and its `message` is the host's sentence;
15+
- the redirect back to a registered `redirect_uri` keeps `error=access_denied`, sends the host's sentence as `error_description`, and adds `objectstack_error_reason` (RFC 6749 §8.2 asks an unregistered parameter to carry a vendor prefix);
16+
- the readable refusal page shows the host's sentence, HTML-escaped, beside the signed-in account.
17+
18+
Nothing the host answers is trusted as markup or as a URL fragment. A reason outside `[a-z_]{1,40}` is dropped and the refusal stands. A sentence with a control character or an angle bracket, or longer than 300 characters, is replaced by the fixed sentence. On the redirect, a sentence outside the character set RFC 6749 §4.1.2.1 allows for `error_description` (printable ASCII without `"` and `\`) is also replaced by the fixed sentence.
19+
20+
On the environment, the OAuth callback for the platform identity provider keeps a valid `objectstack_error_reason` on its redirect to the Console sign-in page. The sign-in page shows its own sentence for `not_member` and `invitation_pending` (in every Console language); any other reason, or none, keeps the existing `access_denied` sentence. The organization's name is carried only inside the host's sentence.
21+
22+
The sign-in page reads the client name only for the client its signed request names: on an OAuth hand-off it asks the new `GET /api/v1/auth/oauth2/client-name` and says "Sign in to continue to NAME". Any other answer keeps the host line ("Continue to HOST"). The read is rate-limited per client address (a fixed window of 10 reads per 60 seconds, counted in the kernel `cache` service when one is registered); over the limit it answers `429` `RATE_LIMIT_EXCEEDED` with `Retry-After`.
23+
24+
Unchanged: a gate that answers a boolean is answered byte for byte as before on all three doors; who is admitted (an object refuses only when it says `allowed: false`; any other answer keeps the truthiness the gate was always read with); which `redirect_uri` is followed.
25+
26+
Upgrade note: a host may return the refusal object only once it runs this plugin-auth release or later. An older plugin-auth reads any object as an admission.

‎packages/plugins/plugin-auth/src/auth-manager-after-hook.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { passwordSignInDoorOf } from './auth-manager-sign-in-lockout.js';
4848
import { narrowDirectoryForExternalCaller } from './external-directory-door.js';
4949
import { SESSION_SCOPING_REFUSAL } from './organization-access-policy.js';
5050
import { refuseIntrospectionForBannedSubject } from './oauth-token-read-ban-refusal.js';
51+
import { carryRefusalReasonOnCallback } from './oauth-callback-refusal-reason.js';
5152
import { rotateCallerBearerOnImpersonation } from './impersonation-bearer-rotation.js';
5253
import { stampInvitationDeliveryOutcome } from './invitation-delivery-outcome.js';
5354
import { retireExpiredInvitationsOnReissue } from './invitation-expired-supersede.js';
@@ -230,6 +231,10 @@ export async function globalAfterHook(this: AfterHookHost, ctx: any) {
230231
// See `sso-provider-lifecycle.ts`.
231232
if (ctx?.path === SSO_PROVIDER_DELETE_PATH) await this.settleSsoProviderDelete(ctx);
232233

234+
// A refused platform sign-in: the environment's callback hands the host's
235+
// reason on to the sign-in page (`oauth-callback-refusal-reason.ts`).
236+
carryRefusalReasonOnCallback(ctx);
237+
233238
// Ruling record 6866334319: an OIDC provider saved with "sign out of the
234239
// company sign-in too" on keeps the end_session_endpoint its before-hook
235240
// read (`sso-sign-out-of-idp.ts`).

‎packages/plugins/plugin-auth/src/auth-manager-before-hook.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
LAST_LOCAL_CREDENTIAL_CODE,
7070
LAST_LOCAL_CREDENTIAL_MESSAGE,
7171
} from './last-local-credential.js';
72-
import { answerRefusedAuthorization } from './oauth-authorize-refusal.js';
72+
import { answerRefusedAuthorization, gateAnswerRefuses, refusalDetailOf } from './oauth-authorize-refusal.js';
7373
import { refuseRequestNamingDifferentAccounts } from './one-account-per-request.js';
7474
import {
7575
SSO_ONLY_RESET_UNREADABLE_MESSAGE,
@@ -601,19 +601,27 @@ export async function globalBeforeHook(
601601
// D5.1 host contract is `(userId, clientId)` and the control plane
602602
// derives org membership / app assignment from the user itself.
603603
if (actor?.userId) {
604-
let allowed = true;
604+
// The first refusing answer, kept: a boolean `false`, or the host's
605+
// refusal object with its reason and sentence.
606+
let refusal: { answer: unknown } | undefined;
605607
for (const clientId of clientIds) {
606-
allowed = await this.config.oidcAuthorizeGate({ userId: actor.userId, clientId });
607-
if (!allowed) break;
608+
const answer: unknown = await this.config.oidcAuthorizeGate({ userId: actor.userId, clientId });
609+
if (gateAnswerRefuses(answer)) {
610+
refusal = { answer };
611+
break;
612+
}
608613
}
609-
if (!allowed) {
614+
if (refusal) {
610615
// The refusal, delivered by who is asking (`oauth-authorize-refusal.ts`):
611-
// the `403` envelope for a fetch or an API client, unchanged; for a
612-
// browser navigating here, `access_denied` back to the client's
613-
// REGISTERED `redirect_uri`, or a readable page when there is none.
616+
// the `403` envelope for a fetch or an API client; for a browser
617+
// navigating here, `access_denied` back to the client's REGISTERED
618+
// `redirect_uri`, or a readable page when there is none. A boolean
619+
// refusal is answered as it always was; a refusal object adds the
620+
// host's validated reason and sentence (`refusalDetailOf`).
614621
return answerRefusedAuthorization(ctx, {
615622
userId: actor.userId,
616623
consoleUrl: this.getConsolePageUrl('/'),
624+
detail: refusalDetailOf(refusal.answer),
617625
});
618626
}
619627
}

‎packages/plugins/plugin-auth/src/auth-manager.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ import { publicBaseUrlOf } from './public-base-url.js';
324324
import { assertTrustedAppSchemes, registeredAppSchemesOf } from './one-time-token-handoff.js';
325325
import type { MintScimConnectionCredentialInput, MintedScimConnectionCredential } from './scim-connection-service.js';
326326
import type { OrganizationBoundaryJudge } from './scim-group-projection.js';
327+
import type { OidcAuthorizeGateAnswer, OidcAuthorizeGateRefusal } from './oauth-authorize-refusal.js';
327328

328329
/**
329330
* Detect WebContainer (StackBlitz) environment.
@@ -971,8 +972,13 @@ export interface AuthManagerOptions extends Partial<AuthConfig> {
971972
* may only obtain a code for an env client (`project_<envId>`) of an org
972973
* they belong to. Unset (open editions / self-host, where the OP is not a
973974
* multi-tenant issuer) = allow. Host is expected to fail CLOSED on error.
975+
*
976+
* In place of `false` the gate may answer an {@link OidcAuthorizeGateRefusal}
977+
* (`{ allowed: false, reason, message }`) to say why: the refusal then
978+
* carries the reason and the host's sentence to the caller
979+
* (`oauth-authorize-refusal.ts`). A boolean is answered as it always was.
974980
*/
975-
oidcAuthorizeGate?: (params: { userId: string; clientId: string }) => boolean | Promise<boolean>;
981+
oidcAuthorizeGate?: (params: { userId: string; clientId: string }) => OidcAuthorizeGateAnswer | Promise<OidcAuthorizeGateAnswer>;
976982

977983
/**
978984
* The host's own check on `POST /organization/delete`: answer a

‎packages/plugins/plugin-auth/src/auth-plugin.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ export class AuthPlugin implements Plugin {
726726
private authSettingsBinding: Promise<void> | null = null;
727727
/** [#26020] The per-address window of the signed-out invitation preview counts here; set in `init()`. */
728728
private invitationPreviewCounters: (() => Promise<CounterStore>) | null = null;
729+
/** The per-address window of the signed-out application-name read counts here; set in `init()`. */
730+
private oauthClientNameCounters: (() => Promise<CounterStore>) | null = null;
729731

730732
constructor(options: AuthPluginOptions = {}) {
731733
this.options = {
@@ -901,6 +903,16 @@ export class AuthPlugin implements Plugin {
901903
'The limit is still enforced, but PER NODE: an N-node deployment admits up to N× the configured ' +
902904
'previews per address per window',
903905
});
906+
// The signed-out application-name read (`oauth-client-name.ts`): the
907+
// same per-address window, under its own subject.
908+
this.oauthClientNameCounters = createLazyCounterStore({
909+
resolveCache,
910+
logger: ctx.logger,
911+
subject: 'signed-out application name rate limit',
912+
degradedImpact:
913+
'The limit is still enforced, but PER NODE: an N-node deployment admits up to N× the configured ' +
914+
'reads per address per window',
915+
});
904916
}
905917

906918
this.applyEnvSocialProviderFallbacks(authConfig);
@@ -5312,6 +5324,45 @@ export class AuthPlugin implements Plugin {
53125324
}
53135325
});
53145326

5327+
// ────────────────────────────────────────────────────────────────────
5328+
// The application name for a sign-in hand-off: the sign-in page reads the
5329+
// client name only for the client its signed request names. The reasons
5330+
// for each answer live in oauth-client-name.ts. It never reads the
5331+
// session, and it is rate-limited per client address (ADR-0121 D6), like
5332+
// the invitation preview above. Ledgered `public` in auth-route-ledger.ts.
5333+
rawApp.get(`${basePath}/oauth2/client-name`, async (c: any) => {
5334+
try {
5335+
const counters = this.oauthClientNameCounters;
5336+
const mgr = this.authManager!;
5337+
if (!counters) {
5338+
ctx.logger.error('[AuthPlugin] oauth2/client-name: the rate-limit store was never wired; refusing');
5339+
return c.json(
5340+
{ success: false, error: { code: 'INTERNAL_ERROR', message: 'The application name is unavailable.' } },
5341+
500,
5342+
{ 'Cache-Control': 'no-store' },
5343+
);
5344+
}
5345+
const { answerOAuthClientName } = await import('./oauth-client-name.js');
5346+
const headers = (c.req.header() ?? {}) as Record<string, string>;
5347+
const answer = await answerOAuthClientName(
5348+
{
5349+
queries: (c.req.queries() ?? {}) as Record<string, string[]>,
5350+
clientAddress: mgr.resolveClientAddress({ headers, ...transportOf(c) }),
5351+
},
5352+
{
5353+
getAuthContext: () => mgr.getAuthContext(),
5354+
getDataEngine: () => mgr.getDataEngine() as any,
5355+
counterStore: counters,
5356+
},
5357+
);
5358+
return c.json(answer.body, answer.status as any, answer.headers);
5359+
} catch (error) {
5360+
const err = error instanceof Error ? error : new Error(String(error));
5361+
ctx.logger.error('[AuthPlugin] oauth2/client-name failed', err);
5362+
return c.json({ success: false, error: { code: 'INTERNAL_ERROR', message: 'The application name is unavailable.' } }, 500);
5363+
}
5364+
});
5365+
53155366
// ────────────────────────────────────────────────────────────────────
53165367
// The mobile sign-in hand-off: a session signed in in the SYSTEM browser
53175368
// is handed to a REGISTERED app scheme as a single-use, one-minute token

‎packages/plugins/plugin-auth/src/auth-route-ledger.conformance.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ describe('auth route ledger hygiene', () => {
248248
// it to the same proof — better-auth serves no address read.
249249
'GET /api/v1/auth/client-address',
250250
'GET /api/v1/auth/config',
251+
// The sign-in hand-off's application name, on this pin's own terms:
252+
// `auth-plugin.ts` mounts it itself (a `rawApp.get` on the
253+
// `${basePath}/oauth2/client-name` template, ahead of the catch-all),
254+
// and the `live.has(route)` loop below holds it to the same proof —
255+
// the vendor serves no route on that path.
256+
'GET /api/v1/auth/oauth2/client-name',
251257
// On this pin's own terms: `auth-plugin.ts` mounts it itself (a
252258
// `rawApp.get` on the `${basePath}/one-time-token/handoff`
253259
// template, ahead of the catch-all), and the `live.has(route)` loop

‎packages/plugins/plugin-auth/src/auth-route-ledger.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ export const AUTH_ROUTE_LEDGER: readonly AuthRouteLedgerEntry[] = [
181181
{ route: 'GET /api/v1/auth/oauth2/get-client', family: 'oauth-provider', source: 'better-auth', disposition: 'sdk', client: 'oauth.applications.get', requires: 'oidcProvider' },
182182
{ route: 'GET /api/v1/auth/oauth2/get-clients', family: 'oauth-provider', source: 'better-auth', disposition: 'sdk', client: 'oauth.applications.list', requires: 'oidcProvider' },
183183
{ route: 'GET /api/v1/auth/oauth2/public-client', family: 'oauth-provider', source: 'better-auth', disposition: 'sdk', client: 'oauth.applications.getPublic', requires: 'oidcProvider' },
184+
// The application name a sign-in hand-off shows (`oauth-client-name.ts`).
185+
{ route: 'GET /api/v1/auth/oauth2/client-name', family: 'oauth-provider', source: 'objectstack', disposition: 'public', note: 'no SDK method builds this URL — the Console sign-in page reads it on an OAuth hand-off. The sign-in page reads the client name only for the client its signed request names: it answers a caller with NO session, admitted by the signed authorization request this server put on the sign-in URL (oauth_query, verified with the provider\'s own verifyOAuthQueryParams, not expired), for the one client_id inside it; the URL\'s client_id must equal that one. Returns exactly { client_name }. One uniform 404 for a signature that does not verify or has expired, a client_id that differs, an unknown, disabled or unnamed client; closed query set { client_id, oauth_query }; Cache-Control no-store. The mount is unconditional: with no OAuth provider there is no signed request, so every call answers the 404' },
184186
{ route: 'GET /api/v1/auth/bootstrap-status', family: 'objectstack-mount', source: 'objectstack', disposition: 'sdk', client: 'auth.bootstrapStatus' },
185187
{ route: 'GET /api/v1/auth/config', family: 'objectstack-mount', source: 'objectstack', disposition: 'sdk', client: 'auth.getConfig' },
186188
// Direct sign-in's start door (`direct-sign-in.ts`): mounted only while the

0 commit comments

Comments
 (0)