@fabrika/iam-contract 0.9.0-dev.34 → 0.9.0-dev.35

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": "@fabrika/iam-contract",
3
- "version": "0.9.0-dev.34",
3
+ "version": "0.9.0-dev.35",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  "test": "bun test"
28
28
  },
29
29
  "dependencies": {
30
- "@fabrika/app": "0.9.0-dev.34",
31
- "@fabrika/auth-core": "0.9.0-dev.34",
32
- "@fabrika/proxy-core": "0.9.0-dev.34"
30
+ "@fabrika/app": "0.9.0-dev.35",
31
+ "@fabrika/auth-core": "0.9.0-dev.35",
32
+ "@fabrika/proxy-core": "0.9.0-dev.35"
33
33
  }
34
34
  }
package/src/oauth.ts CHANGED
@@ -12,11 +12,25 @@ function isOAuthClientProvider(value: unknown): value is OAuthClientProvider {
12
12
  return OAUTH_CLIENT_PROVIDERS.some((provider) => provider === value)
13
13
  }
14
14
 
15
+ /**
16
+ * The one resource an identity-only client is served: its own, outside the installation. A token for it carries the
17
+ * person's identity and no permission, under `app`, an id no installation service or application holds.
18
+ */
19
+ export interface OAuthIdentityResource {
20
+ app: string
21
+ resource: string
22
+ }
23
+
24
+ /** The one scope of an identity resource: it names the person and grants nothing. */
25
+ export const OAUTH_IDENTITY_SCOPE = 'identity'
26
+
15
27
  /** Managed CIMD registrations only; public dynamic registration is not part of this contract. */
16
28
  export interface OAuthManagedClient {
17
29
  provider: OAuthClientProvider
18
30
  clientId: string
19
31
  redirectUris: string[]
32
+ /** Present only on an `external` client: it is served this resource alone, never a registered one. */
33
+ identity?: OAuthIdentityResource
20
34
  }
21
35
 
22
36
  /** RFC 7523 §2.2: the `client_assertion_type` of a JWT client assertion (`private_key_jwt`). */
@@ -189,11 +203,31 @@ export function parseOAuthManagedClient(value: unknown): OAuthManagedClient | nu
189
203
  const provider = field(value, 'provider')
190
204
  const clientId = field(value, 'clientId')
191
205
  const uris = redirectUris(field(value, 'redirectUris'))
192
- return isOAuthClientProvider(provider) && isCimdClientId(clientId) && uris !== null
193
- ? { provider, clientId, redirectUris: uris }
206
+ const rawIdentity = field(value, 'identity')
207
+ if (!isOAuthClientProvider(provider) || !isCimdClientId(clientId) || uris === null) return null
208
+ if (rawIdentity === undefined) return { provider, clientId, redirectUris: uris }
209
+ const identity = parseOAuthIdentityResource(rawIdentity)
210
+ // Claude and ChatGPT are authoring clients; only an external application signs people in for itself.
211
+ return identity === null || provider !== 'external' ? null : { provider, clientId, redirectUris: uris, identity }
212
+ }
213
+
214
+ const IDENTITY_KEYS = ['app', 'resource']
215
+ /** An app id as every fabrika config writes one; no `@`, so never an application environment's id. */
216
+ const IDENTITY_APP = /^[a-z0-9][a-z0-9-]{0,62}$/
217
+
218
+ function parseOAuthIdentityResource(value: unknown): OAuthIdentityResource | null {
219
+ const app = field(value, 'app')
220
+ const resource = field(value, 'resource')
221
+ return hasOnlyKeys(value, IDENTITY_KEYS) && typeof app === 'string' && IDENTITY_APP.test(app) && isOAuthResourceUri(resource)
222
+ ? { app, resource }
194
223
  : null
195
224
  }
196
225
 
226
+ /** The scopes an identity resource's authorization asks for: none, or exactly `identity`. */
227
+ export function resolveOAuthIdentityScopes(scope: string | undefined): string[] | null {
228
+ return scope === undefined || scope === OAUTH_IDENTITY_SCOPE ? [OAUTH_IDENTITY_SCOPE] : null
229
+ }
230
+
197
231
  /** A fetched document cannot enlarge the managed registration's exact redirect allowlist. */
198
232
  export function parseOAuthClientMetadata(value: unknown, registration: OAuthManagedClient): OAuthClientMetadataDocument | null {
199
233
  const managed = parseOAuthManagedClient(registration)
@@ -5,11 +5,23 @@ import type { KeyGrant } from '@fabrika/auth-core';
5
5
  */
6
6
  export declare const OAUTH_CLIENT_PROVIDERS: readonly ["claude", "chatgpt", "external"];
7
7
  export type OAuthClientProvider = (typeof OAUTH_CLIENT_PROVIDERS)[number];
8
+ /**
9
+ * The one resource an identity-only client is served: its own, outside the installation. A token for it carries the
10
+ * person's identity and no permission, under `app`, an id no installation service or application holds.
11
+ */
12
+ export interface OAuthIdentityResource {
13
+ app: string;
14
+ resource: string;
15
+ }
16
+ /** The one scope of an identity resource: it names the person and grants nothing. */
17
+ export declare const OAUTH_IDENTITY_SCOPE = "identity";
8
18
  /** Managed CIMD registrations only; public dynamic registration is not part of this contract. */
9
19
  export interface OAuthManagedClient {
10
20
  provider: OAuthClientProvider;
11
21
  clientId: string;
12
22
  redirectUris: string[];
23
+ /** Present only on an `external` client: it is served this resource alone, never a registered one. */
24
+ identity?: OAuthIdentityResource;
13
25
  }
14
26
  /** RFC 7523 §2.2: the `client_assertion_type` of a JWT client assertion (`private_key_jwt`). */
15
27
  export declare const OAUTH_CLIENT_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
@@ -165,6 +177,8 @@ export interface OAuthAuthorizationServerMetadata {
165
177
  client_id_metadata_document_supported: true;
166
178
  }
167
179
  export declare function parseOAuthManagedClient(value: unknown): OAuthManagedClient | null;
180
+ /** The scopes an identity resource's authorization asks for: none, or exactly `identity`. */
181
+ export declare function resolveOAuthIdentityScopes(scope: string | undefined): string[] | null;
168
182
  /** A fetched document cannot enlarge the managed registration's exact redirect allowlist. */
169
183
  export declare function parseOAuthClientMetadata(value: unknown, registration: OAuthManagedClient): OAuthClientMetadataDocument | null;
170
184
  export declare function parseOAuthResourceDto(value: unknown): OAuthResourceDto | null;