Skip to content

Commit ce9c9eb

Browse files
feat(auth): pairing grants access and T3 Connect management by default
Ordinary pairing codes, T3 Connect sign-ins and the hosted app got a standard grant without access:read, access:write and relay:write, so phones and Connect sessions could not see Connections, approve an outside agent without a pairing code, or mint pairing codes. The split was not a boundary: the same grant holds terminal:operate and orchestration:operate, and a shell or a full-access agent can mint a session with every scope through `t3 auth session issue`. The standard set now includes access and relay management, and the separate administrative preset is gone; its uses point at the standard set. Explicit --scope and the Connections scope picker still narrow a grant, and stored grants are never widened. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 51f7382 commit ce9c9eb

16 files changed

Lines changed: 52 additions & 64 deletions

File tree

‎apps/server/src/auth/EnvironmentAuth.test.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import {
3-
authScopeResponse,
4-
AuthAdministrativeScopes,
5-
AuthStandardClientScopes,
6-
} from "@t3tools/contracts";
2+
import { authScopeResponse, AuthStandardClientScopes } from "@t3tools/contracts";
73
import { expect, it } from "@effect/vitest";
84
import * as Effect from "effect/Effect";
95
import * as Layer from "effect/Layer";
@@ -103,7 +99,7 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
10399
const authenticated = yield* serverAuth.authenticateHttpRequest(request);
104100
expect(devExchange.cookieName).toMatch(/^t3_dev_session_/);
105101
expect(devExchange.expireNormalCookie).toBe(true);
106-
expect(devExchange.response).toMatchObject(authScopeResponse(AuthAdministrativeScopes));
102+
expect(devExchange.response).toMatchObject(authScopeResponse(AuthStandardClientScopes));
107103
expect(authenticated.scopes).toEqual(["orchestration:read"]);
108104
}).pipe(
109105
Effect.provide(
@@ -253,7 +249,7 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
253249
expect((yield* Effect.flip(sessions.verify(token)))._tag).toBe("SessionTokenRevokedError");
254250
expect(
255251
(yield* serverAuth.createBrowserSession(recovery.credential, requestMetadata)).response,
256-
).toMatchObject({ authenticated: true, ...authScopeResponse(AuthAdministrativeScopes) });
252+
).toMatchObject({ authenticated: true, ...authScopeResponse(AuthStandardClientScopes) });
257253
}).pipe(
258254
Effect.provide(
259255
layerEnvironmentAuth({
@@ -362,7 +358,9 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
362358
it.effect("preserves pairing grants after rejecting scopes they do not grant", () =>
363359
Effect.gen(function* () {
364360
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
365-
const pairingCredential = yield* serverAuth.issuePairingCredential();
361+
const pairingCredential = yield* serverAuth.issuePairingCredential({
362+
scopes: ["orchestration:read", "orchestration:operate"],
363+
});
366364

367365
const error = yield* serverAuth
368366
.exchangeBootstrapCredentialForAccessToken(
@@ -514,7 +512,7 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
514512
Effect.gen(function* () {
515513
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
516514
const pairingCredential = yield* serverAuth.issuePairingCredential({
517-
scopes: AuthAdministrativeScopes,
515+
scopes: AuthStandardClientScopes,
518516
});
519517
const listedPairingLinks = yield* serverAuth.listPairingLinks();
520518

@@ -544,7 +542,7 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
544542
makeCookieRequest(sessions.cookieName, exchanged.sessionToken),
545543
);
546544

547-
expect(verified.scopes).toEqual(AuthAdministrativeScopes);
545+
expect(verified.scopes).toEqual(AuthStandardClientScopes);
548546
expect(verified.subject).toBe("administrative-bootstrap");
549547
}).pipe(Effect.provide(layerEnvironmentAuth())),
550548
);

‎apps/server/src/auth/EnvironmentAuth.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
AuthAccessTokenType,
33
AuthAccessWriteScope,
4-
AuthAdministrativeScopes,
54
AuthOrchestrationOperateScope,
65
AuthOrchestrationReadScope,
76
AuthSettingsWriteScope,
@@ -1096,7 +1095,7 @@ export const make = Effect.gen(function* () {
10961095
.issue({
10971096
subject: input?.subject ?? DEFAULT_SESSION_SUBJECT,
10981097
method: "bearer-access-token",
1099-
scopes: input?.scopes ?? AuthAdministrativeScopes,
1098+
scopes: input?.scopes ?? AuthStandardClientScopes,
11001099
client: {
11011100
...(input?.label ? { label: input.label } : {}),
11021101
deviceType: "bot",
@@ -1151,7 +1150,7 @@ export const make = Effect.gen(function* () {
11511150
const issueStartupPairingCredential: EnvironmentAuth["Service"]["issueStartupPairingCredential"] =
11521151
() => {
11531152
const fallback = issuePairingCredentialForSubject({
1154-
scopes: AuthAdministrativeScopes,
1153+
scopes: AuthStandardClientScopes,
11551154
subject: INTERNAL_ADMINISTRATIVE_BOOTSTRAP_SUBJECT,
11561155
purpose: "startup",
11571156
});

‎apps/server/src/auth/EnvironmentAuthAdmin.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthAdministrativeScopes } from "@t3tools/contracts";
1+
import { AuthStandardClientScopes } from "@t3tools/contracts";
22
import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { expect, it } from "@effect/vitest";
44
import * as Effect from "effect/Effect";
@@ -80,11 +80,11 @@ it.layer(NodeServices.layer)("EnvironmentAuth administrative operations", (it) =
8080
const listedAfterRevoke = yield* environmentAuth.listSessions();
8181

8282
expect(issued.method).toBe("bearer-access-token");
83-
expect(issued.scopes).toEqual(AuthAdministrativeScopes);
83+
expect(issued.scopes).toEqual(AuthStandardClientScopes);
8484
expect(issued.client.deviceType).toBe("bot");
8585
expect(issued.client.label).toBe("deploy-bot");
8686
expect(verified.sessionId).toBe(issued.sessionId);
87-
expect(verified.scopes).toEqual(AuthAdministrativeScopes);
87+
expect(verified.scopes).toEqual(AuthStandardClientScopes);
8888
expect(verified.method).toBe("bearer-access-token");
8989
expect(listedBeforeRevoke).toHaveLength(1);
9090
expect(listedBeforeRevoke[0]?.sessionId).toBe(issued.sessionId);

‎apps/server/src/auth/McpOAuth.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import {
3-
AuthAdministrativeScopes,
3+
AuthStandardClientScopes,
44
type AuthCreatePairingCredentialInput,
55
EnvironmentHttpApi,
66
} from "@t3tools/contracts";
@@ -502,7 +502,7 @@ it.live("one-click approves only access the browser session holds the scopes for
502502
Effect.flatMap(json<{ csrfToken?: string; oneClickAccess?: ReadonlyArray<string> }>),
503503
);
504504

505-
const admin = yield* browserCookie([...AuthAdministrativeScopes]);
505+
const admin = yield* browserCookie([...AuthStandardClientScopes]);
506506
const adminDetails = yield* details(admin);
507507
expect(adminDetails.csrfToken).toEqual(expect.any(String));
508508
expect(adminDetails.oneClickAccess).toEqual([

‎apps/server/src/auth/PairingGrantStore.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthAdministrativeScopes, AuthStandardClientScopes } from "@t3tools/contracts";
1+
import { AuthStandardClientScopes } from "@t3tools/contracts";
22
import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { expect, it } from "@effect/vitest";
44
import * as Duration from "effect/Duration";
@@ -163,7 +163,7 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
163163
const third = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
164164

165165
expect(first.method).toBe("desktop-bootstrap");
166-
expect(first.scopes).toEqual(AuthAdministrativeScopes);
166+
expect(first.scopes).toEqual(AuthStandardClientScopes);
167167
expect(first.subject).toBe("desktop-bootstrap");
168168
expect(second.method).toBe("desktop-bootstrap");
169169
expect(third.method).toBe("desktop-bootstrap");

‎apps/server/src/auth/PairingGrantStore.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AuthAdministrativeScopes,
32
AuthStandardClientScopes,
43
type AuthEnvironmentScope,
54
type AuthPairingLink,
@@ -316,7 +315,7 @@ export const make = Effect.gen(function* () {
316315
const now = yield* DateTime.now;
317316
yield* seedGrant(config.desktopBootstrapToken, {
318317
method: "desktop-bootstrap",
319-
scopes: AuthAdministrativeScopes,
318+
scopes: AuthStandardClientScopes,
320319
subject: "desktop-bootstrap",
321320
expiresAt: DateTime.add(now, {
322321
milliseconds: Duration.toMillis(DESKTOP_BOOTSTRAP_TTL_HOURS),
@@ -441,7 +440,7 @@ export const make = Effect.gen(function* () {
441440
if (consumeRotatingDesktopToken(credential, now.epochMilliseconds)) {
442441
return {
443442
method: "desktop-bootstrap",
444-
scopes: AuthAdministrativeScopes,
443+
scopes: AuthStandardClientScopes,
445444
subject: "desktop-bootstrap",
446445
expiresAt: DateTime.add(now, {
447446
milliseconds: DESKTOP_BOOTSTRAP_TOKEN_WINDOW_MS,

‎apps/server/src/auth/SessionStore.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
AuthSessionId,
3-
AuthAdministrativeScopes,
43
AuthStandardClientScopes,
54
AuthEnvironmentScopes,
65
type AuthClientMetadata,
@@ -508,7 +507,7 @@ export const make = Effect.gen(function* () {
508507
.createIfAbsent({
509508
sessionId: devAuth.sessionId,
510509
subject: "reusable-dev-token",
511-
scopes: AuthAdministrativeScopes,
510+
scopes: AuthStandardClientScopes,
512511
method: "browser-session-cookie",
513512
client: {
514513
label: "Reusable dev token",

‎apps/server/src/cli/auth.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
AuthAdministrativeScopes,
3-
AuthSessionId,
4-
AuthStandardClientScopes,
5-
} from "@t3tools/contracts";
1+
import { AuthSessionId, AuthStandardClientScopes } from "@t3tools/contracts";
62
import * as Console from "effect/Console";
73
import * as Effect from "effect/Effect";
84
import * as Layer from "effect/Layer";
@@ -163,7 +159,7 @@ const pairingCommand = Command.make("pairing").pipe(
163159

164160
const sessionIssueCommand = Command.make("issue", {
165161
...authLocationFlags,
166-
scopes: authScopesFlag(AuthAdministrativeScopes),
162+
scopes: authScopesFlag(AuthStandardClientScopes),
167163
ttl: ttlFlag,
168164
label: labelFlag,
169165
subject: subjectFlag,

‎apps/server/src/cli/project.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AuthAdministrativeScopes,
2+
AuthStandardClientScopes,
33
CommandId,
44
EnvironmentHttpApi,
55
EnvironmentHttpCommonError,
@@ -221,7 +221,7 @@ const withProjectCliSessionToken = <A, E, R>(
221221
) =>
222222
Effect.acquireUseRelease(
223223
environmentAuth.issueSession({
224-
scopes: AuthAdministrativeScopes,
224+
scopes: AuthStandardClientScopes,
225225
label: "t3 project cli",
226226
}),
227227
(issued) => run(issued.token),

‎apps/web/src/components/cloud/ConnectOnboardingDialog.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { useAuth } from "@clerk/react";
22
import { useAtomValue } from "@effect/atom-react";
3-
import {
4-
AuthAdministrativeScopes,
5-
AuthRelayReadScope,
6-
AuthRelayWriteScope,
7-
type AuthSessionState,
8-
} from "@t3tools/contracts";
3+
import { AuthRelayReadScope, AuthRelayWriteScope, type AuthSessionState } from "@t3tools/contracts";
94
import { AsyncResult, Atom } from "effect/reactivity";
105
import { useEffect, useRef, useState } from "react";
116

0 commit comments

Comments
 (0)