@segmentstream/ontology 0.202.0 → 0.203.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/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/dist/analyze.js +13 -0
- package/dist/manifest.d.ts +19 -0
- package/dist/manifest.js +6 -0
- package/dist/migrate/model.d.ts +8 -0
- package/dist/service/federation-provider.d.ts +11 -3
- package/dist/service/federation-provider.js +67 -34
- package/dist/service/mcp/listing.d.ts +10 -2
- package/dist/service/mcp/listing.js +19 -14
- package/dist/service/mcp/server.js +1 -1
- package/dist/service/oauth/protocol.d.ts +3 -0
- package/dist/service/oauth/protocol.js +3 -0
- package/dist/service/oauth/server.d.ts +15 -0
- package/dist/service/oauth/server.js +59 -10
- package/dist/service/schemas.d.ts +2 -0
- package/dist/service/service.js +20 -1
- package/dist/sign-in.d.ts +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.203.0
|
|
4
|
+
|
|
5
|
+
`signIn.cli: true` lets members' SegmentStream CLI reach the app's MCP server without a device
|
|
6
|
+
link. A member who has signed in to the app with SegmentStream and allowed it gets their grant from
|
|
7
|
+
a CLI signed in to SegmentStream: SegmentStream signs a five-minute token for the app, and the
|
|
8
|
+
app's OAuth token endpoint exchanges it (RFC 8693 token exchange) for the grant a device link
|
|
9
|
+
gives. The app's OAuth metadata then lists the token-exchange grant and SegmentStream's client for
|
|
10
|
+
the app. It needs `signIn.browser.methods` to include `segmentstream`, never links or enrolls
|
|
11
|
+
anyone, and is off when omitted.
|
|
12
|
+
|
|
13
|
+
## 0.202.1
|
|
14
|
+
|
|
15
|
+
A `tools/list` cursor now survives a redeploy of the app between pages. The listing resumes after
|
|
16
|
+
the last tool it returned, or at that tool's position when the new catalog no longer has it, so MCP
|
|
17
|
+
clients no longer fail to load a workspace's tools while it is being deployed. A cursor from other
|
|
18
|
+
permissions is still refused.
|
|
19
|
+
|
|
3
20
|
## 0.202.0
|
|
4
21
|
|
|
5
22
|
A member of staff answers the chat of someone the agent never admitted. Recording a channel
|
package/README.md
CHANGED
|
@@ -1677,7 +1677,7 @@ with the built-in action `user_identity.attach({ user, provider, subject, userna
|
|
|
1677
1677
|
account, and is a conflict for another member's live account or a second account of the
|
|
1678
1678
|
provider. No other action writes `user_identity`. Revoked bindings are omitted; identity subjects are
|
|
1679
1679
|
stable and usernames are mutable display metadata. Older databases without channel tables
|
|
1680
|
-
remain readable. Use `segmentstream
|
|
1680
|
+
remain readable. Use `segmentstream app member list --via PROVIDER` to find a member UUID.
|
|
1681
1681
|
|
|
1682
1682
|
### The workspace's code
|
|
1683
1683
|
|
package/dist/analyze.js
CHANGED
|
@@ -1623,6 +1623,7 @@ function signInOptions(config, report) {
|
|
|
1623
1623
|
"onNewUser",
|
|
1624
1624
|
"browser",
|
|
1625
1625
|
"codeLink",
|
|
1626
|
+
"cli",
|
|
1626
1627
|
"invitationEmail",
|
|
1627
1628
|
"linkEmail",
|
|
1628
1629
|
"codeEmail",
|
|
@@ -1674,6 +1675,17 @@ function signInOptions(config, report) {
|
|
|
1674
1675
|
if (codeLink !== undefined && typeof codeLink !== "boolean") {
|
|
1675
1676
|
report("invalid-sign-in", "signIn.codeLink", "codeLink takes true or false.");
|
|
1676
1677
|
}
|
|
1678
|
+
const cli = options.cli;
|
|
1679
|
+
if (cli !== undefined && typeof cli !== "boolean") {
|
|
1680
|
+
report("invalid-sign-in", "signIn.cli", "cli takes true or false.");
|
|
1681
|
+
}
|
|
1682
|
+
else if (cli === true &&
|
|
1683
|
+
!(isPlainObject(options.browser) &&
|
|
1684
|
+
Array.isArray(options.browser.methods) &&
|
|
1685
|
+
options.browser.methods.includes("segmentstream"))) {
|
|
1686
|
+
report("invalid-sign-in", "signIn.cli", 'cli needs signIn.browser.methods to include "segmentstream": ' +
|
|
1687
|
+
"the CLI acts for members who sign in with SegmentStream.");
|
|
1688
|
+
}
|
|
1677
1689
|
return {
|
|
1678
1690
|
policy: options.policy,
|
|
1679
1691
|
...(options.browser === undefined || browserError
|
|
@@ -1682,6 +1694,7 @@ function signInOptions(config, report) {
|
|
|
1682
1694
|
...(Object.keys(channels).length > 0 ? { channels } : {}),
|
|
1683
1695
|
...(typeof hook === "string" ? { onNewUser: hook } : {}),
|
|
1684
1696
|
...(typeof codeLink === "boolean" ? { codeLink } : {}),
|
|
1697
|
+
...(typeof cli === "boolean" ? { cli } : {}),
|
|
1685
1698
|
};
|
|
1686
1699
|
}
|
|
1687
1700
|
const SIGN_IN_EMAILS = {
|
package/dist/manifest.d.ts
CHANGED
|
@@ -116,6 +116,9 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
116
116
|
* Within version 16, an action may carry `anyOf`, written only when several permissions open it,
|
|
117
117
|
* as the built-in `agent_chat.send` is: any one of them runs it, and `permission` is the first.
|
|
118
118
|
* Older readers show the action as requiring `permission` alone.
|
|
119
|
+
* Within version 16, `signIn` may carry `cli: true`, written only when declared: members'
|
|
120
|
+
* SegmentStream CLI may exchange a token SegmentStream signs for them for a grant to the app,
|
|
121
|
+
* without a device link. Older readers ignore it; their services do not offer the exchange.
|
|
119
122
|
*/
|
|
120
123
|
export declare const MANIFEST_VERSION = 16;
|
|
121
124
|
/** The phrase used for a direction the author did not phrase. */
|
|
@@ -868,6 +871,8 @@ export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
|
|
|
868
871
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
869
872
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
870
873
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
874
|
+
/** Whether members' SegmentStream CLI may exchange a SegmentStream token for a grant. */
|
|
875
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
871
876
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
872
877
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
873
878
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -1258,6 +1263,8 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1258
1263
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
1259
1264
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
1260
1265
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
1266
|
+
/** Whether members' SegmentStream CLI may exchange a SegmentStream token for a grant. */
|
|
1267
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
1261
1268
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
1262
1269
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
1263
1270
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -1888,6 +1895,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1888
1895
|
} | undefined;
|
|
1889
1896
|
readonly onNewUser?: string | undefined;
|
|
1890
1897
|
readonly codeLink?: boolean | undefined;
|
|
1898
|
+
readonly cli?: boolean | undefined;
|
|
1891
1899
|
readonly signUp?: {
|
|
1892
1900
|
readonly channels: {
|
|
1893
1901
|
readonly [x: string]: unknown;
|
|
@@ -2273,6 +2281,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2273
2281
|
} | undefined;
|
|
2274
2282
|
readonly onNewUser?: string | undefined;
|
|
2275
2283
|
readonly codeLink?: boolean | undefined;
|
|
2284
|
+
readonly cli?: boolean | undefined;
|
|
2276
2285
|
readonly signUp?: {
|
|
2277
2286
|
readonly channels: {
|
|
2278
2287
|
readonly [x: string]: unknown;
|
|
@@ -2735,6 +2744,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2735
2744
|
readonly channels?: {
|
|
2736
2745
|
readonly [x: string]: unknown;
|
|
2737
2746
|
} | undefined;
|
|
2747
|
+
readonly cli?: boolean | undefined;
|
|
2738
2748
|
readonly on_new_user?: string | undefined;
|
|
2739
2749
|
readonly code_link?: boolean | undefined;
|
|
2740
2750
|
readonly sign_up?: {
|
|
@@ -3041,6 +3051,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3041
3051
|
readonly channels?: {
|
|
3042
3052
|
readonly [x: string]: unknown;
|
|
3043
3053
|
} | undefined;
|
|
3054
|
+
readonly cli?: boolean | undefined;
|
|
3044
3055
|
readonly on_new_user?: string | undefined;
|
|
3045
3056
|
readonly code_link?: boolean | undefined;
|
|
3046
3057
|
readonly sign_up?: {
|
|
@@ -3347,6 +3358,8 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3347
3358
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
3348
3359
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
3349
3360
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
3361
|
+
/** Whether members' SegmentStream CLI may exchange a SegmentStream token for a grant. */
|
|
3362
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
3350
3363
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
3351
3364
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
3352
3365
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -3881,6 +3894,8 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3881
3894
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
3882
3895
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
3883
3896
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
3897
|
+
/** Whether members' SegmentStream CLI may exchange a SegmentStream token for a grant. */
|
|
3898
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
3884
3899
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
3885
3900
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
3886
3901
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -4503,6 +4518,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4503
4518
|
} | undefined;
|
|
4504
4519
|
readonly onNewUser?: string | undefined;
|
|
4505
4520
|
readonly codeLink?: boolean | undefined;
|
|
4521
|
+
readonly cli?: boolean | undefined;
|
|
4506
4522
|
readonly signUp?: {
|
|
4507
4523
|
readonly channels: {
|
|
4508
4524
|
readonly [x: string]: unknown;
|
|
@@ -4888,6 +4904,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4888
4904
|
} | undefined;
|
|
4889
4905
|
readonly onNewUser?: string | undefined;
|
|
4890
4906
|
readonly codeLink?: boolean | undefined;
|
|
4907
|
+
readonly cli?: boolean | undefined;
|
|
4891
4908
|
readonly signUp?: {
|
|
4892
4909
|
readonly channels: {
|
|
4893
4910
|
readonly [x: string]: unknown;
|
|
@@ -5279,6 +5296,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5279
5296
|
} | undefined;
|
|
5280
5297
|
readonly onNewUser?: string | undefined;
|
|
5281
5298
|
readonly codeLink?: boolean | undefined;
|
|
5299
|
+
readonly cli?: boolean | undefined;
|
|
5282
5300
|
readonly signUp?: {
|
|
5283
5301
|
readonly channels: {
|
|
5284
5302
|
readonly [x: string]: unknown;
|
|
@@ -5664,6 +5682,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5664
5682
|
} | undefined;
|
|
5665
5683
|
readonly onNewUser?: string | undefined;
|
|
5666
5684
|
readonly codeLink?: boolean | undefined;
|
|
5685
|
+
readonly cli?: boolean | undefined;
|
|
5667
5686
|
readonly signUp?: {
|
|
5668
5687
|
readonly channels: {
|
|
5669
5688
|
readonly [x: string]: unknown;
|
package/dist/manifest.js
CHANGED
|
@@ -117,6 +117,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
117
117
|
* Within version 16, an action may carry `anyOf`, written only when several permissions open it,
|
|
118
118
|
* as the built-in `agent_chat.send` is: any one of them runs it, and `permission` is the first.
|
|
119
119
|
* Older readers show the action as requiring `permission` alone.
|
|
120
|
+
* Within version 16, `signIn` may carry `cli: true`, written only when declared: members'
|
|
121
|
+
* SegmentStream CLI may exchange a token SegmentStream signs for them for a grant to the app,
|
|
122
|
+
* without a device link. Older readers ignore it; their services do not offer the exchange.
|
|
120
123
|
*/
|
|
121
124
|
export const MANIFEST_VERSION = 16;
|
|
122
125
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -544,6 +547,8 @@ export const SignInManifest = Schema.Struct({
|
|
|
544
547
|
channels: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
|
|
545
548
|
onNewUser: Schema.optionalKey(Schema.String),
|
|
546
549
|
codeLink: Schema.optionalKey(Schema.Boolean),
|
|
550
|
+
/** Whether members' SegmentStream CLI may exchange a SegmentStream token for a grant. */
|
|
551
|
+
cli: Schema.optionalKey(Schema.Boolean),
|
|
547
552
|
signUp: Schema.optionalKey(SignUpManifest),
|
|
548
553
|
onSignUp: Schema.optionalKey(Schema.String),
|
|
549
554
|
guest: Schema.optionalKey(GuestManifest),
|
|
@@ -1187,6 +1192,7 @@ export function buildManifest(input) {
|
|
|
1187
1192
|
...(input.signIn.browser === undefined ? {} : { browser: input.signIn.browser }),
|
|
1188
1193
|
...(input.signIn.onNewUser === undefined ? {} : { onNewUser: input.signIn.onNewUser }),
|
|
1189
1194
|
...(input.signIn.codeLink === undefined ? {} : { codeLink: input.signIn.codeLink }),
|
|
1195
|
+
...(input.signIn.cli === undefined ? {} : { cli: input.signIn.cli }),
|
|
1190
1196
|
...(input.signIn.invitationEmail === undefined
|
|
1191
1197
|
? {}
|
|
1192
1198
|
: { invitationEmail: input.signIn.invitationEmail }),
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -584,6 +584,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
584
584
|
} | undefined;
|
|
585
585
|
readonly onNewUser?: string | undefined;
|
|
586
586
|
readonly codeLink?: boolean | undefined;
|
|
587
|
+
readonly cli?: boolean | undefined;
|
|
587
588
|
readonly signUp?: {
|
|
588
589
|
readonly channels: {
|
|
589
590
|
readonly [x: string]: unknown;
|
|
@@ -969,6 +970,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
969
970
|
} | undefined;
|
|
970
971
|
readonly onNewUser?: string | undefined;
|
|
971
972
|
readonly codeLink?: boolean | undefined;
|
|
973
|
+
readonly cli?: boolean | undefined;
|
|
972
974
|
readonly signUp?: {
|
|
973
975
|
readonly channels: {
|
|
974
976
|
readonly [x: string]: unknown;
|
|
@@ -1431,6 +1433,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1431
1433
|
readonly channels?: {
|
|
1432
1434
|
readonly [x: string]: unknown;
|
|
1433
1435
|
} | undefined;
|
|
1436
|
+
readonly cli?: boolean | undefined;
|
|
1434
1437
|
readonly on_new_user?: string | undefined;
|
|
1435
1438
|
readonly code_link?: boolean | undefined;
|
|
1436
1439
|
readonly sign_up?: {
|
|
@@ -1737,6 +1740,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1737
1740
|
readonly channels?: {
|
|
1738
1741
|
readonly [x: string]: unknown;
|
|
1739
1742
|
} | undefined;
|
|
1743
|
+
readonly cli?: boolean | undefined;
|
|
1740
1744
|
readonly on_new_user?: string | undefined;
|
|
1741
1745
|
readonly code_link?: boolean | undefined;
|
|
1742
1746
|
readonly sign_up?: {
|
|
@@ -1986,6 +1990,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1986
1990
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
1987
1991
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
1988
1992
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
1993
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
1989
1994
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
1990
1995
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
1991
1996
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -2367,6 +2372,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2367
2372
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
2368
2373
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
2369
2374
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
2375
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
2370
2376
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
2371
2377
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
2372
2378
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -2901,6 +2907,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2901
2907
|
} | undefined;
|
|
2902
2908
|
readonly onNewUser?: string | undefined;
|
|
2903
2909
|
readonly codeLink?: boolean | undefined;
|
|
2910
|
+
readonly cli?: boolean | undefined;
|
|
2904
2911
|
readonly signUp?: {
|
|
2905
2912
|
readonly channels: {
|
|
2906
2913
|
readonly [x: string]: unknown;
|
|
@@ -3286,6 +3293,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
3286
3293
|
} | undefined;
|
|
3287
3294
|
readonly onNewUser?: string | undefined;
|
|
3288
3295
|
readonly codeLink?: boolean | undefined;
|
|
3296
|
+
readonly cli?: boolean | undefined;
|
|
3289
3297
|
readonly signUp?: {
|
|
3290
3298
|
readonly channels: {
|
|
3291
3299
|
readonly [x: string]: unknown;
|
|
@@ -29,8 +29,16 @@ export declare function createFederationProvider(config: {
|
|
|
29
29
|
clientId: string;
|
|
30
30
|
generation: number;
|
|
31
31
|
consentId: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* The member a CLI token names: Cloud signed it for this client and deployment within the
|
|
35
|
+
* last five minutes, for a member who signed in with SegmentStream and allowed the app.
|
|
36
|
+
*/
|
|
37
|
+
verifyCliToken: (token: string) => Promise<{
|
|
38
|
+
issuer: string;
|
|
39
|
+
subject: string;
|
|
40
|
+
clientId: string;
|
|
41
|
+
generation: number;
|
|
42
|
+
consentId: string;
|
|
35
43
|
}>;
|
|
36
44
|
};
|
|
@@ -29,6 +29,53 @@ export function createFederationProvider(config, options = {}) {
|
|
|
29
29
|
discovery = undefined;
|
|
30
30
|
throw cause;
|
|
31
31
|
}));
|
|
32
|
+
/**
|
|
33
|
+
* A token Cloud signed for this app's client and deployment, verified offline: an ID token that
|
|
34
|
+
* signs a member in, which carries a nonce, or a token a member's CLI exchanges for a grant,
|
|
35
|
+
* which carries `ss_use: "cli"` and no nonce. Neither stands in for the other.
|
|
36
|
+
*/
|
|
37
|
+
const verified = async (token, jwksUri, use) => {
|
|
38
|
+
const label = use === "sign_in" ? "ID token" : "CLI token";
|
|
39
|
+
keys ??= createRemoteJWKSet(new URL(jwksUri), { timeoutDuration: 5000 });
|
|
40
|
+
const { payload } = await jwtVerify(token, keys, {
|
|
41
|
+
algorithms: ["ES256"],
|
|
42
|
+
issuer: config.issuer,
|
|
43
|
+
audience: config.clientId,
|
|
44
|
+
requiredClaims: use === "sign_in" ? ["sub", "nonce", "auth_time", "iat", "exp"] : ["sub", "iat", "exp"],
|
|
45
|
+
maxTokenAge: 300,
|
|
46
|
+
});
|
|
47
|
+
if (payload.aud !== config.clientId) {
|
|
48
|
+
throw new Error(`OIDC ${label} audience must be the single public client ID`);
|
|
49
|
+
}
|
|
50
|
+
if (use === "sign_in"
|
|
51
|
+
? payload.ss_use !== undefined
|
|
52
|
+
: payload.ss_use !== "cli" || payload.nonce !== undefined) {
|
|
53
|
+
throw new Error(`OIDC ${label} is of another use`);
|
|
54
|
+
}
|
|
55
|
+
if (!payload.sub) {
|
|
56
|
+
throw new Error(`OIDC ${label} subject is missing`);
|
|
57
|
+
}
|
|
58
|
+
if (payload.exp - payload.iat > 300) {
|
|
59
|
+
throw new Error(`OIDC ${label} lifetime exceeds five minutes`);
|
|
60
|
+
}
|
|
61
|
+
if (!Number.isInteger(payload.ss_generation) || typeof payload.ss_consent !== "string") {
|
|
62
|
+
throw new Error(`OIDC ${label} lacks the client generation or consent reference`);
|
|
63
|
+
}
|
|
64
|
+
if (config.environment &&
|
|
65
|
+
(payload.ss_environment !== config.environment ||
|
|
66
|
+
payload.ss_manifest_digest !== config.manifestDigest ||
|
|
67
|
+
(config.environment !== "local" && payload.ss_deployment_id !== config.deploymentId))) {
|
|
68
|
+
throw new Error("OIDC deployment binding mismatch");
|
|
69
|
+
}
|
|
70
|
+
return payload;
|
|
71
|
+
};
|
|
72
|
+
const binding = () => config.environment
|
|
73
|
+
? {
|
|
74
|
+
environment: config.environment,
|
|
75
|
+
manifestDigest: config.manifestDigest,
|
|
76
|
+
...(config.deploymentId ? { deploymentId: config.deploymentId } : {}),
|
|
77
|
+
}
|
|
78
|
+
: {};
|
|
32
79
|
return {
|
|
33
80
|
metadata,
|
|
34
81
|
exchange: async (input) => {
|
|
@@ -55,45 +102,15 @@ export function createFederationProvider(config, options = {}) {
|
|
|
55
102
|
const diagnostic = [input.code, input.verifier, input.nonce].reduce((text, credential) => (credential ? text.split(credential).join("[redacted]") : text), explanation);
|
|
56
103
|
throw new Error(`OIDC code exchange failed (${response.status}): ${diagnostic || "no ID token"}`);
|
|
57
104
|
}
|
|
58
|
-
|
|
59
|
-
const { payload } = await jwtVerify(body.id_token, keys, {
|
|
60
|
-
algorithms: ["ES256"],
|
|
61
|
-
issuer: config.issuer,
|
|
62
|
-
audience: config.clientId,
|
|
63
|
-
requiredClaims: ["sub", "nonce", "auth_time", "iat", "exp"],
|
|
64
|
-
maxTokenAge: 300,
|
|
65
|
-
});
|
|
66
|
-
if (payload.aud !== config.clientId) {
|
|
67
|
-
throw new Error("OIDC ID token audience must be the single public client ID");
|
|
68
|
-
}
|
|
105
|
+
const payload = await verified(body.id_token, document.jwks_uri, "sign_in");
|
|
69
106
|
if (payload.nonce !== input.nonce) {
|
|
70
107
|
throw new Error("OIDC ID token nonce does not match this login");
|
|
71
108
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
payload.auth_time > payload.iat) {
|
|
75
|
-
throw new Error("OIDC ID token subject or authentication time is invalid");
|
|
76
|
-
}
|
|
77
|
-
if (payload.exp - payload.iat > 300) {
|
|
78
|
-
throw new Error("OIDC ID token lifetime exceeds five minutes");
|
|
79
|
-
}
|
|
80
|
-
if (!Number.isInteger(payload.ss_generation) || typeof payload.ss_consent !== "string") {
|
|
81
|
-
throw new Error("OIDC ID token lacks the client generation or consent reference");
|
|
82
|
-
}
|
|
83
|
-
if (config.environment &&
|
|
84
|
-
(payload.ss_environment !== config.environment ||
|
|
85
|
-
payload.ss_manifest_digest !== config.manifestDigest ||
|
|
86
|
-
(config.environment !== "local" && payload.ss_deployment_id !== config.deploymentId))) {
|
|
87
|
-
throw new Error("OIDC deployment binding mismatch");
|
|
109
|
+
if (typeof payload.auth_time !== "number" || payload.auth_time > payload.iat) {
|
|
110
|
+
throw new Error("OIDC ID token authentication time is invalid");
|
|
88
111
|
}
|
|
89
112
|
return {
|
|
90
|
-
...(
|
|
91
|
-
? {
|
|
92
|
-
environment: config.environment,
|
|
93
|
-
manifestDigest: config.manifestDigest,
|
|
94
|
-
...(config.deploymentId ? { deploymentId: config.deploymentId } : {}),
|
|
95
|
-
}
|
|
96
|
-
: {}),
|
|
113
|
+
...binding(),
|
|
97
114
|
issuer: config.issuer,
|
|
98
115
|
subject: payload.sub,
|
|
99
116
|
clientId: config.clientId,
|
|
@@ -106,5 +123,21 @@ export function createFederationProvider(config, options = {}) {
|
|
|
106
123
|
...(typeof payload.name === "string" ? { name: payload.name } : {}),
|
|
107
124
|
};
|
|
108
125
|
},
|
|
126
|
+
/**
|
|
127
|
+
* The member a CLI token names: Cloud signed it for this client and deployment within the
|
|
128
|
+
* last five minutes, for a member who signed in with SegmentStream and allowed the app.
|
|
129
|
+
*/
|
|
130
|
+
verifyCliToken: async (token) => {
|
|
131
|
+
const document = await metadata();
|
|
132
|
+
const payload = await verified(token, document.jwks_uri, "cli");
|
|
133
|
+
return {
|
|
134
|
+
...binding(),
|
|
135
|
+
issuer: config.issuer,
|
|
136
|
+
subject: payload.sub,
|
|
137
|
+
clientId: config.clientId,
|
|
138
|
+
generation: payload.ss_generation,
|
|
139
|
+
consentId: payload.ss_consent,
|
|
140
|
+
};
|
|
141
|
+
},
|
|
109
142
|
};
|
|
110
143
|
}
|
|
@@ -19,8 +19,16 @@ export declare function toolDefinition(tool: McpTool): {
|
|
|
19
19
|
openWorldHint: boolean;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Standard MCP operation definitions; pagination never substitutes search or dispatch tools.
|
|
24
|
+
*
|
|
25
|
+
* A cursor names the last tool it listed, its position and the caller's permissions. A listing
|
|
26
|
+
* survives a redeploy of the app between pages: it resumes after that tool in the current
|
|
27
|
+
* catalog, or at its position when the tool is gone, since clients do not restart a listing whose
|
|
28
|
+
* cursor is refused. A cursor from other permissions is refused, so no page lists a tool the
|
|
29
|
+
* caller may not use.
|
|
30
|
+
*/
|
|
31
|
+
export declare function listTools(tools: ReadonlyArray<McpTool>, principal: PermissionHolder, caller: CallerContext, cursor?: unknown): {
|
|
24
32
|
tools: Array<ReturnType<typeof toolDefinition>>;
|
|
25
33
|
nextCursor?: string;
|
|
26
34
|
};
|
|
@@ -24,16 +24,19 @@ function invalidCursor() {
|
|
|
24
24
|
detail: "The tool-list cursor is invalid or the catalog or permissions changed. Restart tools/list.",
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Standard MCP operation definitions; pagination never substitutes search or dispatch tools.
|
|
29
|
+
*
|
|
30
|
+
* A cursor names the last tool it listed, its position and the caller's permissions. A listing
|
|
31
|
+
* survives a redeploy of the app between pages: it resumes after that tool in the current
|
|
32
|
+
* catalog, or at its position when the tool is gone, since clients do not restart a listing whose
|
|
33
|
+
* cursor is refused. A cursor from other permissions is refused, so no page lists a tool the
|
|
34
|
+
* caller may not use.
|
|
35
|
+
*/
|
|
36
|
+
export function listTools(tools, principal, caller, cursor) {
|
|
29
37
|
const visible = visibleTools(tools, principal, caller);
|
|
30
38
|
const scope = createHash("sha256")
|
|
31
|
-
.update(JSON.stringify([
|
|
32
|
-
hash,
|
|
33
|
-
caller.kind,
|
|
34
|
-
[...new Set(principal.permissions)].sort(),
|
|
35
|
-
visible.map(({ name }) => name),
|
|
36
|
-
]))
|
|
39
|
+
.update(JSON.stringify([caller.kind, [...new Set(principal.permissions)].sort()]))
|
|
37
40
|
.digest("hex");
|
|
38
41
|
let start = 0;
|
|
39
42
|
if (cursor !== undefined) {
|
|
@@ -51,16 +54,18 @@ export function listTools(tools, principal, caller, hash, cursor) {
|
|
|
51
54
|
decoded === null ||
|
|
52
55
|
!("scope" in decoded) ||
|
|
53
56
|
!("last" in decoded) ||
|
|
57
|
+
!("at" in decoded) ||
|
|
54
58
|
decoded.scope !== scope ||
|
|
55
|
-
typeof decoded.last !== "string"
|
|
59
|
+
typeof decoded.last !== "string" ||
|
|
60
|
+
typeof decoded.at !== "number" ||
|
|
61
|
+
!Number.isSafeInteger(decoded.at) ||
|
|
62
|
+
decoded.at < 0) {
|
|
56
63
|
return invalidCursor();
|
|
57
64
|
}
|
|
58
65
|
const last = decoded.last;
|
|
59
66
|
const position = visible.findIndex(({ name }) => name === last);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
start = position + 1;
|
|
67
|
+
// Gone from the catalog: the tool after it now holds its position.
|
|
68
|
+
start = position >= 0 ? position + 1 : Math.min(decoded.at, visible.length);
|
|
64
69
|
}
|
|
65
70
|
// Eve 0.85 calls listTools once, unlike AI SDK's tools() which follows nextCursor.
|
|
66
71
|
// Keep deployed runtime clients working; both paths expose the same direct operations.
|
|
@@ -85,7 +90,7 @@ export function listTools(tools, principal, caller, hash, cursor) {
|
|
|
85
90
|
tools: selected,
|
|
86
91
|
...(last !== undefined && start + selected.length < visible.length
|
|
87
92
|
? {
|
|
88
|
-
nextCursor: Buffer.from(JSON.stringify({ scope, last: last.name })).toString("base64url"),
|
|
93
|
+
nextCursor: Buffer.from(JSON.stringify({ scope, last: last.name, at: start + selected.length - 1 })).toString("base64url"),
|
|
89
94
|
}
|
|
90
95
|
: {}),
|
|
91
96
|
};
|
|
@@ -701,7 +701,7 @@ function dispatch(server, message, request) {
|
|
|
701
701
|
return rpcResult(id, {});
|
|
702
702
|
case "tools/list": {
|
|
703
703
|
return yield* Effect.try({
|
|
704
|
-
try: () => listTools(server.tools, principal, caller,
|
|
704
|
+
try: () => listTools(server.tools, principal, caller, params.cursor),
|
|
705
705
|
catch: (error) => error,
|
|
706
706
|
}).pipe(Effect.map((result) => rpcResult(id, result)), Effect.catchIf((error) => error instanceof DiscoveryError, (error) => Effect.succeed(rpcError(id, INVALID_PARAMS, error.detail))));
|
|
707
707
|
}
|
|
@@ -63,6 +63,9 @@ export declare function callerOfAccessToken(store: OAuthStore, token: string, re
|
|
|
63
63
|
readonly grantId: string;
|
|
64
64
|
} | undefined>;
|
|
65
65
|
export declare const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
66
|
+
/** RFC 8693: a member's SegmentStream CLI exchanges a token SegmentStream signed for a grant. */
|
|
67
|
+
export declare const TOKEN_EXCHANGE_GRANT = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
68
|
+
export declare const JWT_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:jwt";
|
|
66
69
|
export declare const DEVICE_TTL_MS: number;
|
|
67
70
|
export declare const DEVICE_INTERVAL = 5;
|
|
68
71
|
/** 32 symbols, five bits per symbol, without ambiguous I/O/0/1. */
|
|
@@ -152,6 +152,9 @@ export function callerOfAccessToken(store, token, resource) {
|
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
export const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
155
|
+
/** RFC 8693: a member's SegmentStream CLI exchanges a token SegmentStream signed for a grant. */
|
|
156
|
+
export const TOKEN_EXCHANGE_GRANT = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
157
|
+
export const JWT_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:jwt";
|
|
155
158
|
export const DEVICE_TTL_MS = 10 * 60 * 1000;
|
|
156
159
|
export const DEVICE_INTERVAL = 5;
|
|
157
160
|
/** 32 symbols, five bits per symbol, without ambiguous I/O/0/1. */
|
|
@@ -15,9 +15,24 @@ export declare function mcpResource(origin: string): string;
|
|
|
15
15
|
* which is how a client learns where members authorize it (RFC 9728).
|
|
16
16
|
*/
|
|
17
17
|
export declare function mcpChallenge(origin: string, missing: boolean): string;
|
|
18
|
+
/**
|
|
19
|
+
* The ontology's opt-in (`signIn.cli`) to grants for members' SegmentStream CLI, by RFC 8693
|
|
20
|
+
* token exchange of a token SegmentStream signs for this app's client and deployment.
|
|
21
|
+
*/
|
|
22
|
+
export interface CliExchange {
|
|
23
|
+
/** SegmentStream's client for this app, which the CLI names when it asks for a token. */
|
|
24
|
+
readonly clientId: string;
|
|
25
|
+
/** The SegmentStream identity a CLI token names; rejects every other token. */
|
|
26
|
+
readonly verify: (token: string) => Promise<{
|
|
27
|
+
readonly issuer: string;
|
|
28
|
+
readonly subject: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
18
31
|
export interface OAuthServerOptions {
|
|
19
32
|
readonly verifyToken: TokenVerifier;
|
|
20
33
|
readonly refreshReuseGraceMs?: number;
|
|
34
|
+
/** Absent: the token endpoint does not offer the exchange. */
|
|
35
|
+
readonly cliExchange?: CliExchange;
|
|
21
36
|
}
|
|
22
37
|
/**
|
|
23
38
|
* The MCP server's OAuth 2.1 authorization server, on the app's own origin: the protected resource
|
|
@@ -7,7 +7,7 @@ import { CurrentPrincipal, withPrincipal } from "../authentication.js";
|
|
|
7
7
|
import { RequestId, errorBodyForWire } from "../errors.js";
|
|
8
8
|
import { fixedWindowLimiter, clientAddress } from "../rate-limit.js";
|
|
9
9
|
import { OntologyBackend, } from "../runtime-contract.js";
|
|
10
|
-
import { ACCESS_TOKEN_PREFIX, appSessionResource, ACCESS_TOKEN_TTL_MS, AUTHORIZATION_SERVER_PATH, CLIENT_ID_PREFIX, CLIENT_SECRET_PREFIX, CODE_PREFIX, CODE_TTL_MS, DEVICE_GRANT, DEVICE_TTL_MS, DEVICE_INTERVAL, humanCode, normalizedUserCode, CONSENT_PATH, FULL_SCOPE, PROTECTED_RESOURCE_PATH, READ_SCOPE, REFRESH_TOKEN_PREFIX, REFRESH_TOKEN_TTL_MS, REQUEST_TTL_MS, SCOPES, grantedScope, isLoopback, newSecret, publicOrigin, sameSecret, sameResource, secretHash, verifierMatches, } from "./protocol.js";
|
|
10
|
+
import { ACCESS_TOKEN_PREFIX, appSessionResource, ACCESS_TOKEN_TTL_MS, AUTHORIZATION_SERVER_PATH, CLIENT_ID_PREFIX, CLIENT_SECRET_PREFIX, CODE_PREFIX, CODE_TTL_MS, DEVICE_GRANT, JWT_TOKEN_TYPE, TOKEN_EXCHANGE_GRANT, DEVICE_TTL_MS, DEVICE_INTERVAL, humanCode, normalizedUserCode, CONSENT_PATH, FULL_SCOPE, PROTECTED_RESOURCE_PATH, READ_SCOPE, REFRESH_TOKEN_PREFIX, REFRESH_TOKEN_TTL_MS, REQUEST_TTL_MS, SCOPES, grantedScope, isLoopback, newSecret, publicOrigin, sameSecret, sameResource, secretHash, verifierMatches, } from "./protocol.js";
|
|
11
11
|
import { decryptReplay, encryptReplay } from "./refresh-replay.js";
|
|
12
12
|
/** The authorization server's endpoints, under the ontology service's path. */
|
|
13
13
|
export const OAUTH_PATH = `${BASE_PATH}/oauth`;
|
|
@@ -63,7 +63,7 @@ function protectedResourceMetadata(origin) {
|
|
|
63
63
|
resource_name: "Ontology",
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
function authorizationServerMetadata(origin) {
|
|
66
|
+
function authorizationServerMetadata(origin, cli) {
|
|
67
67
|
const authMethods = [
|
|
68
68
|
"none",
|
|
69
69
|
"client_secret_post",
|
|
@@ -79,11 +79,18 @@ function authorizationServerMetadata(origin) {
|
|
|
79
79
|
response_types_supported: ["code"],
|
|
80
80
|
response_modes_supported: ["query"],
|
|
81
81
|
device_authorization_endpoint: `${origin}${DEVICE_PATH}`,
|
|
82
|
-
grant_types_supported: [
|
|
82
|
+
grant_types_supported: [
|
|
83
|
+
"authorization_code",
|
|
84
|
+
"refresh_token",
|
|
85
|
+
DEVICE_GRANT,
|
|
86
|
+
...(cli ? [TOKEN_EXCHANGE_GRANT] : []),
|
|
87
|
+
],
|
|
83
88
|
token_endpoint_auth_methods_supported: authMethods,
|
|
84
89
|
revocation_endpoint_auth_methods_supported: authMethods,
|
|
85
90
|
code_challenge_methods_supported: ["S256"],
|
|
86
91
|
authorization_response_iss_parameter_supported: true,
|
|
92
|
+
// The client a member's CLI names when it asks SegmentStream for a token to exchange here.
|
|
93
|
+
...(cli ? { segmentstream_client_id: cli.clientId } : {}),
|
|
87
94
|
};
|
|
88
95
|
}
|
|
89
96
|
function searchParams(request) {
|
|
@@ -187,8 +194,10 @@ function register(store, limiter) {
|
|
|
187
194
|
return oauthError("invalid_client_metadata", "Send the client metadata as a JSON object.");
|
|
188
195
|
}
|
|
189
196
|
const metadata = body;
|
|
197
|
+
// A client that never takes the browser's code needs no redirect URI.
|
|
190
198
|
const deviceOnly = Array.isArray(metadata.grant_types) &&
|
|
191
|
-
metadata.grant_types.includes(DEVICE_GRANT)
|
|
199
|
+
(metadata.grant_types.includes(DEVICE_GRANT) ||
|
|
200
|
+
metadata.grant_types.includes(TOKEN_EXCHANGE_GRANT)) &&
|
|
192
201
|
!metadata.grant_types.includes("authorization_code");
|
|
193
202
|
const redirectUris = metadata.redirect_uris ?? (deviceOnly ? [] : undefined);
|
|
194
203
|
if (!Array.isArray(redirectUris) ||
|
|
@@ -212,10 +221,14 @@ function register(store, limiter) {
|
|
|
212
221
|
const grantTypes = metadata.grant_types ?? ["authorization_code"];
|
|
213
222
|
const responseTypes = metadata.response_types ?? (deviceOnly ? [] : ["code"]);
|
|
214
223
|
if (!Array.isArray(grantTypes) ||
|
|
215
|
-
!grantTypes.every((type) => type === "authorization_code" ||
|
|
224
|
+
!grantTypes.every((type) => type === "authorization_code" ||
|
|
225
|
+
type === "refresh_token" ||
|
|
226
|
+
type === DEVICE_GRANT ||
|
|
227
|
+
type === TOKEN_EXCHANGE_GRANT) ||
|
|
216
228
|
!Array.isArray(responseTypes) ||
|
|
217
229
|
!responseTypes.every((type) => type === "code")) {
|
|
218
|
-
return oauthError("invalid_client_metadata", "This server grants authorization_code
|
|
230
|
+
return oauthError("invalid_client_metadata", "This server grants authorization_code, refresh_token, device_code and token-exchange, " +
|
|
231
|
+
"with the code response type.");
|
|
219
232
|
}
|
|
220
233
|
const name = typeof metadata.client_name === "string" && metadata.client_name.trim() !== ""
|
|
221
234
|
? metadata.client_name.trim().slice(0, MAX_NAME_LENGTH)
|
|
@@ -527,13 +540,45 @@ function replayTokens(store, grant, previous, encrypted, graceMs) {
|
|
|
527
540
|
* token and a new refresh token. Refresh retries recover their immediate unused successor; reuse
|
|
528
541
|
* of an older generation revokes the grant. A member who may no longer sign in gets nothing.
|
|
529
542
|
*/
|
|
530
|
-
function token(store, graceMs) {
|
|
543
|
+
function token(store, graceMs, cli) {
|
|
531
544
|
return (request) => Effect.gen(function* () {
|
|
532
545
|
const params = yield* bodyParams(request);
|
|
533
546
|
const client = yield* authenticateClient(store, request, params);
|
|
534
547
|
if (client === undefined) {
|
|
535
548
|
return oauthError("invalid_client", "The client is unknown or its secret is wrong.", 401);
|
|
536
549
|
}
|
|
550
|
+
if (params.grant_type === TOKEN_EXCHANGE_GRANT) {
|
|
551
|
+
if (cli === undefined) {
|
|
552
|
+
return oauthError("unsupported_grant_type", "This app does not let SegmentStream's CLI sign in by token exchange.");
|
|
553
|
+
}
|
|
554
|
+
if (!params.subject_token || params.subject_token_type !== JWT_TOKEN_TYPE) {
|
|
555
|
+
return oauthError("invalid_request", `subject_token and subject_token_type ${JWT_TOKEN_TYPE} are required.`);
|
|
556
|
+
}
|
|
557
|
+
const resource = mcpResource(publicOrigin(request));
|
|
558
|
+
if (params.resource !== undefined && !sameResource(params.resource, resource)) {
|
|
559
|
+
return oauthError("invalid_target", "Use this app's MCP resource.");
|
|
560
|
+
}
|
|
561
|
+
const subjectToken = params.subject_token;
|
|
562
|
+
const identity = yield* Effect.tryPromise(() => cli.exchange.verify(subjectToken)).pipe(Effect.orElseSucceed(() => undefined));
|
|
563
|
+
if (identity === undefined) {
|
|
564
|
+
return oauthError("invalid_grant", "SegmentStream did not sign this token for this app.");
|
|
565
|
+
}
|
|
566
|
+
// Only the user already linked to this SegmentStream account; never links or enrolls.
|
|
567
|
+
const linked = yield* cli.member(identity.issuer, identity.subject);
|
|
568
|
+
const member = linked === undefined ? undefined : yield* store.memberPrincipal(linked.id);
|
|
569
|
+
if (member === undefined) {
|
|
570
|
+
return oauthError("invalid_grant", "No member of this app signs in with this SegmentStream account.");
|
|
571
|
+
}
|
|
572
|
+
const grant = {
|
|
573
|
+
id: randomUUID(),
|
|
574
|
+
clientId: client.id,
|
|
575
|
+
userId: member.id,
|
|
576
|
+
resource,
|
|
577
|
+
scope: grantedScope(params.scope),
|
|
578
|
+
};
|
|
579
|
+
yield* store.saveGrant(grant);
|
|
580
|
+
return yield* issueTokens(store, grant);
|
|
581
|
+
}
|
|
537
582
|
if (params.grant_type === DEVICE_GRANT) {
|
|
538
583
|
if (!params.device_code) {
|
|
539
584
|
return oauthError("invalid_request", "device_code is required.");
|
|
@@ -563,7 +608,7 @@ function token(store, graceMs) {
|
|
|
563
608
|
? "refresh"
|
|
564
609
|
: undefined;
|
|
565
610
|
if (kind === undefined) {
|
|
566
|
-
return oauthError("unsupported_grant_type", "This server supports authorization_code, refresh_token and
|
|
611
|
+
return oauthError("unsupported_grant_type", "This server supports authorization_code, refresh_token, device_code and token-exchange.");
|
|
567
612
|
}
|
|
568
613
|
const presented = kind === "code" ? params.code : params.refresh_token;
|
|
569
614
|
if (presented === undefined) {
|
|
@@ -752,7 +797,11 @@ export function oauthLayer(options) {
|
|
|
752
797
|
yield* router.add("GET", path, metadata(protectedResourceMetadata));
|
|
753
798
|
yield* router.add("OPTIONS", path, PREFLIGHT);
|
|
754
799
|
}
|
|
755
|
-
|
|
800
|
+
const federation = backend.federation;
|
|
801
|
+
const cli = options.cliExchange && federation
|
|
802
|
+
? { exchange: options.cliExchange, member: federation.identity }
|
|
803
|
+
: undefined;
|
|
804
|
+
yield* router.add("GET", AUTHORIZATION_SERVER_PATH, metadata((origin) => authorizationServerMetadata(origin, cli?.exchange)));
|
|
756
805
|
yield* router.add("OPTIONS", AUTHORIZATION_SERVER_PATH, PREFLIGHT);
|
|
757
806
|
yield* router.add("POST", REGISTER_PATH, register(store, limiter));
|
|
758
807
|
yield* router.add("OPTIONS", REGISTER_PATH, PREFLIGHT);
|
|
@@ -762,7 +811,7 @@ export function oauthLayer(options) {
|
|
|
762
811
|
for (const decision of ["lookup", "approve", "deny"]) {
|
|
763
812
|
yield* router.add("POST", `${DEVICE_REQUEST_PATH}/${decision}`, asMember((request) => verifyDevice(store, request, decision, verificationLimiter)));
|
|
764
813
|
}
|
|
765
|
-
yield* router.add("POST", TOKEN_PATH, token(store, options.refreshReuseGraceMs ?? 45_000));
|
|
814
|
+
yield* router.add("POST", TOKEN_PATH, token(store, options.refreshReuseGraceMs ?? 45_000, cli));
|
|
766
815
|
yield* router.add("OPTIONS", TOKEN_PATH, PREFLIGHT);
|
|
767
816
|
yield* router.add("POST", REVOKE_PATH, revoke(store));
|
|
768
817
|
yield* router.add("OPTIONS", REVOKE_PATH, PREFLIGHT);
|
|
@@ -458,6 +458,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
458
458
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
459
459
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
460
460
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
461
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
461
462
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
462
463
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
463
464
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
@@ -854,6 +855,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
854
855
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
855
856
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
856
857
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
858
|
+
readonly cli: Schema.optionalKey<Schema.Boolean>;
|
|
857
859
|
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
858
860
|
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
859
861
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
package/dist/service/service.js
CHANGED
|
@@ -48,6 +48,7 @@ import { runtimeAllows } from "./mcp/runtime-policy.js";
|
|
|
48
48
|
import { suggestNames } from "./name-suggestions.js";
|
|
49
49
|
import { observeMcpRequest } from "./mcp/request-log.js";
|
|
50
50
|
import { oauthLayer } from "./oauth/server.js";
|
|
51
|
+
import { createFederationProvider } from "./federation-provider.js";
|
|
51
52
|
import { federationLayer } from "./federation-server.js";
|
|
52
53
|
import { channelSessionLayer } from "./channel/sessions.js";
|
|
53
54
|
import { channelSignInLayer } from "./channel/sign-in.js";
|
|
@@ -429,9 +430,27 @@ export function createOntologyService(ontology, config) {
|
|
|
429
430
|
signUp: signUpOriginsOf(ontology.manifest),
|
|
430
431
|
};
|
|
431
432
|
const visitors = visitorWebsites.guests.length > 0 || visitorWebsites.signUp.length > 0;
|
|
433
|
+
// `signIn.cli`: members' SegmentStream CLI exchanges a token SegmentStream signed for this
|
|
434
|
+
// app's client and deployment for a grant, as the member who signs in with that account.
|
|
435
|
+
const cliProvider = ontology.signIn.cli === true &&
|
|
436
|
+
federationConfig !== undefined &&
|
|
437
|
+
browser?.methods.includes("segmentstream")
|
|
438
|
+
? createFederationProvider(federationConfig)
|
|
439
|
+
: undefined;
|
|
432
440
|
const oauth = preview
|
|
433
441
|
? Layer.empty
|
|
434
|
-
: oauthLayer({
|
|
442
|
+
: oauthLayer({
|
|
443
|
+
verifyToken,
|
|
444
|
+
refreshReuseGraceMs: config.oauthRefreshReuseGraceMs,
|
|
445
|
+
...(cliProvider && federationConfig
|
|
446
|
+
? {
|
|
447
|
+
cliExchange: {
|
|
448
|
+
clientId: federationConfig.clientId,
|
|
449
|
+
verify: (token) => cliProvider.verifyCliToken(token),
|
|
450
|
+
},
|
|
451
|
+
}
|
|
452
|
+
: {}),
|
|
453
|
+
});
|
|
435
454
|
const mcp = config.mcp === false
|
|
436
455
|
? // A website's visitors renew their agent tokens at the OAuth token endpoint.
|
|
437
456
|
visitors
|
package/dist/sign-in.d.ts
CHANGED
|
@@ -175,6 +175,14 @@ export interface SignInOptions {
|
|
|
175
175
|
* person to confirm. The link signs in whichever browser opens it.
|
|
176
176
|
*/
|
|
177
177
|
readonly codeLink?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Whether a member's SegmentStream CLI, signed in to SegmentStream, may get a grant to the app
|
|
180
|
+
* (its MCP server) without a device link, by exchanging a token SegmentStream signs for it. It
|
|
181
|
+
* acts as the member, with their roles, and only for a member who signs in to the app with
|
|
182
|
+
* SegmentStream: `browser` must offer `segmentstream`, and the member must have signed in with it
|
|
183
|
+
* and allowed the app. It never links or enrolls anyone. Off when omitted.
|
|
184
|
+
*/
|
|
185
|
+
readonly cli?: boolean;
|
|
178
186
|
/**
|
|
179
187
|
* One of the ontology's `emails`, by its camelCase name, that the platform sends instead of its
|
|
180
188
|
* own invitation: when a member is invited from the CLI or the console, and when
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.203.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|