@fabrika/iam-contract 0.9.0-dev.46 → 0.9.0-dev.48

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.46",
3
+ "version": "0.9.0-dev.48",
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.46",
31
- "@fabrika/auth-core": "0.9.0-dev.46",
32
- "@fabrika/proxy-core": "0.9.0-dev.46"
30
+ "@fabrika/app": "0.9.0-dev.48",
31
+ "@fabrika/auth-core": "0.9.0-dev.48",
32
+ "@fabrika/proxy-core": "0.9.0-dev.48"
33
33
  }
34
34
  }
package/src/index.ts CHANGED
@@ -29,8 +29,6 @@ import type { InstallationBrand } from '@fabrika/proxy-core/brand'
29
29
  import type {
30
30
  ExternalAppDto,
31
31
  ExternalAppInput,
32
- ImportOAuthClientsRequest,
33
- ImportOAuthClientsResponse,
34
32
  OAuthClientDto,
35
33
  OAuthClientInput,
36
34
  PutExternalAppRequest,
@@ -50,6 +48,7 @@ import type {
50
48
  } from './passkeys'
51
49
  import type { PasswordPolicyDto, SetPasswordPolicyRequest } from './password-policy'
52
50
  import type { ProvisionRequestedApiKeyRequest, RequestedApiKey, RequestedApiKeyInput, RequestedApiKeyResponse } from './requested-keys'
51
+ import type { ScimSettingsDto, ScimTokenIssuedDto } from './scim'
53
52
 
54
53
  // ── Common wrappers ───────────────────────────────────────────────────────────
55
54
 
@@ -967,8 +966,6 @@ export interface IamAdminRpcContract {
967
966
  list: RpcProcedure<void, ListResponse<OAuthClientDto>>
968
967
  put: RpcProcedure<PutOAuthClientRequest, OAuthClientDto>
969
968
  delete: RpcProcedure<OAuthClientInput, OkResponse>
970
- /** The deploy's one import of its client list, with the provisioning key; every later call writes nothing. */
971
- importOnce: RpcProcedure<ImportOAuthClientsRequest, ImportOAuthClientsResponse>
972
969
  }
973
970
  policies: {
974
971
  list: RpcProcedure<AppInput, ListResponse<PolicyDto>>
@@ -1044,6 +1041,17 @@ export interface IamAdminRpcContract {
1044
1041
  get: RpcProcedure<void, PasswordPolicyDto>
1045
1042
  set: RpcProcedure<SetPasswordPolicyRequest, PasswordPolicyDto>
1046
1043
  }
1044
+ /**
1045
+ * SCIM provisioning by the organization's identity provider (ADR-0091), an installation administrator's in a signed-in
1046
+ * session. `rotateToken` creates the installation's one token or replaces it (the old one stops working at once) and
1047
+ * answers the secret once; `revokeToken` removes it, after which every SCIM request is refused. Each writes
1048
+ * `iam.scim.token.rotate` or `iam.scim.token.revoke`.
1049
+ */
1050
+ scim: {
1051
+ get: RpcProcedure<void, ScimSettingsDto>
1052
+ rotateToken: RpcProcedure<void, ScimTokenIssuedDto>
1053
+ revokeToken: RpcProcedure<void, ScimSettingsDto>
1054
+ }
1047
1055
  /**
1048
1056
  * A person's second factor (TOTP), an installation administrator's (`iam.admin`) to read and to reset. The person
1049
1057
  * enrols at IAM's `SECOND_FACTOR_ENROL_PATH`, never here. A reset removes the authenticator and its recovery codes
@@ -1114,3 +1122,4 @@ export * from './oauth-registry'
1114
1122
  export * from './passkeys'
1115
1123
  export * from './password-policy'
1116
1124
  export * from './requested-keys'
1125
+ export * from './scim'
@@ -4,13 +4,6 @@
4
4
 
5
5
  import type { OAuthClientProvider, OAuthIdentityRole } from './oauth'
6
6
 
7
- /**
8
- * IAM's refusal of a registry write before the deploy imported its client list (release N of ADR-0089), answered with
9
- * HTTP 409. The console and the CLI match it to say what to do instead of showing a generic conflict.
10
- */
11
- export const OAUTH_REGISTRY_NOT_IMPORTED = 'IAM takes registry writes once a deploy of this release has imported the OAuth client list '
12
- + '(oauthClients.importOnce); until then it serves the clients of its OAUTH_CONFIG. Deploy the platform first.'
13
-
14
7
  /** How many clients one external application has. */
15
8
  export const MAX_EXTERNAL_APP_CLIENTS = 16
16
9
 
@@ -37,7 +30,7 @@ export interface PutExternalAppRequest {
37
30
 
38
31
  export interface ExternalAppDto {
39
32
  app: string
40
- /** Null for an application the deploy variable's import registered, which named none. */
33
+ /** Null for an application an earlier release's import of the deploy variable registered, which named none. */
41
34
  name: string | null
42
35
  resource: string
43
36
  /** Null when the application declares no roles. */
@@ -73,15 +66,3 @@ export interface PutOAuthClientRequest {
73
66
  export interface OAuthClientInput {
74
67
  clientId: string
75
68
  }
76
-
77
- /**
78
- * The deploy variable's list, imported once (release N of ADR-0089): each entry in the shape `OAUTH_CONFIG.clients`
79
- * takes, an `OAuthManagedClient` with an optional `metadataUrl`. IAM checks every entry again.
80
- */
81
- export interface ImportOAuthClientsRequest {
82
- clients: unknown[]
83
- }
84
-
85
- export type ImportOAuthClientsResponse =
86
- | { status: 'imported'; externalApps: string[]; oauthClients: string[] }
87
- | { status: 'already_imported' }
package/src/oauth.ts CHANGED
@@ -1,4 +1,13 @@
1
- import { BUILTIN_ROLE_KEYS, isCimdClientId, isOAuthClientId, isOAuthResourceUri, parseOAuthScopes } from '@fabrika/auth-core'
1
+ import {
2
+ AGENT_CLIENT_ID,
3
+ BUILTIN_ROLE_KEYS,
4
+ isAgentLabel,
5
+ isCimdClientId,
6
+ isOAuthClientId,
7
+ isOAuthResourceUri,
8
+ isScopeParameterText,
9
+ parseOAuthScopes,
10
+ } from '@fabrika/auth-core'
2
11
  import type { KeyGrant } from '@fabrika/auth-core'
3
12
 
4
13
  /**
@@ -139,8 +148,11 @@ export type OAuthTokenRequest =
139
148
  /** RFC 8628 §3.1, with every resource the grant is asked for (RFC 8707): each token names one of them. */
140
149
  export interface OAuthDeviceAuthorizationRequest {
141
150
  client_id: string
151
+ /** Empty only for the agent client, which then asks for its default scope (ADR-0090 §2). */
142
152
  scope: string[]
143
153
  resources: string[]
154
+ /** The agent client's name for itself, shown to the person as the agent's own words; ignored for any other client. */
155
+ agent_label?: string
144
156
  }
145
157
 
146
158
  /** RFC 8628 §3.2. */
@@ -416,11 +428,6 @@ function parseResourcePermissions(value: unknown): KeyGrant[] | null {
416
428
  /** Separates a parameterized scope from its value: `deploy:alpha`. */
417
429
  export const SCOPE_PARAMETER_SEPARATOR = ':'
418
430
 
419
- /** A scope dimension type, or a value of one, as a scope token may carry it. */
420
- function isScopeParameterText(value: unknown): value is string {
421
- return typeof value === 'string' && value.length <= 100 && /^[A-Za-z0-9][A-Za-z0-9._@-]*$/.test(value)
422
- }
423
-
424
431
  /**
425
432
  * The resource's grant a requested scope token selects and the narrowed permissions it holds, or null when the token
426
433
  * selects none: an unknown scope, a parameterized scope without its value, a value on a scope that takes none.
@@ -507,22 +514,28 @@ export function parseOAuthTokenRequest(value: unknown): OAuthTokenRequest | null
507
514
  }
508
515
 
509
516
  /**
510
- * A device authorization request: its client, at least one scope and one to `MAX_OAUTH_DEVICE_RESOURCES` distinct
511
- * resources. `resource` is the one parameter that may repeat (RFC 8707 §2), so the caller collects it into a list.
517
+ * A device authorization request: its client, at least one scope (the agent client may name none) and one to
518
+ * `MAX_OAUTH_DEVICE_RESOURCES` distinct resources. `resource` is the one parameter that may repeat (RFC 8707 §2), so the
519
+ * caller collects it into a list.
512
520
  */
513
521
  export function parseOAuthDeviceAuthorizationRequest(
514
522
  value: { fields: Record<string, string>; resources: string[] },
515
523
  ): OAuthDeviceAuthorizationRequest | null {
516
524
  const clientId = field(value.fields, 'client_id')
517
525
  const scope = field(value.fields, 'scope')
518
- if (!isOAuthClientId(clientId) || typeof scope !== 'string') return null
519
- const scopes = parseOAuthScopes(scope.split(' '))
526
+ if (!isOAuthClientId(clientId)) return null
527
+ const agent = clientId === AGENT_CLIENT_ID
528
+ // The agent client may omit the scope, and a parameter without a value is omitted (RFC 6749 §3.1); IAM then picks `read`.
529
+ const scopes = agent && (scope === undefined || scope === '') ? [] : typeof scope === 'string' ? parseOAuthScopes(scope.split(' ')) : null
520
530
  const resources = value.resources
521
531
  if (
522
- scopes === null || scopes.length === 0 || resources.length === 0 || resources.length > MAX_OAUTH_DEVICE_RESOURCES
532
+ scopes === null || (scopes.length === 0 && !agent) || resources.length === 0 || resources.length > MAX_OAUTH_DEVICE_RESOURCES
523
533
  || !resources.every(isOAuthResourceUri) || new Set(resources).size !== resources.length
524
534
  ) return null
525
- return { client_id: clientId, scope: scopes, resources: [...resources] }
535
+ const label = field(value.fields, 'agent_label')
536
+ if (!agent || label === undefined) return { client_id: clientId, scope: scopes, resources: [...resources] }
537
+ if (typeof label !== 'string' || !isAgentLabel(label)) return null
538
+ return { client_id: clientId, scope: scopes, resources: [...resources], agent_label: label }
526
539
  }
527
540
 
528
541
  export function isOAuthDeviceGrantLifetime(value: number): value is OAuthDeviceGrantLifetime {
package/src/scim.ts ADDED
@@ -0,0 +1,19 @@
1
+ // SCIM provisioning (ADR-0091): the organization's identity provider creates, updates and deprovisions the
2
+ // installation's users at IAM's `/scim/v2`, with one bearer token an installation administrator creates and rotates.
3
+
4
+ /** The installation's SCIM provisioning as the console shows it. */
5
+ export interface ScimSettingsDto {
6
+ /** The tenant URL an identity provider is configured with: IAM's origin and `/scim/v2`. */
7
+ endpoint: string
8
+ /** Whether a token exists; without one IAM refuses every SCIM request. */
9
+ configured: boolean
10
+ /** When the current token was created, in epoch seconds; null without one. */
11
+ createdAt: number | null
12
+ }
13
+
14
+ /** A token just created: the secret is in this answer and nowhere else, ever again. */
15
+ export interface ScimTokenIssuedDto extends ScimSettingsDto {
16
+ configured: true
17
+ createdAt: number
18
+ token: string
19
+ }
@@ -1,10 +1,11 @@
1
1
  import type { RpcProcedureContract } from '@fabrika/app';
2
2
  import type { AppActionDef, AppDelegationDef, AppLinkMountDef, AppMemberItem, AppSchema, AppScopeDef, DimensionValue, Locale, PermissionEntry, PermissionSource, PrincipalAffiliation, PrincipalType, RoleDef, WorkloadKind } from '@fabrika/auth-core';
3
3
  import type { InstallationBrand } from '@fabrika/proxy-core/brand';
4
- import type { ExternalAppDto, ExternalAppInput, ImportOAuthClientsRequest, ImportOAuthClientsResponse, OAuthClientDto, OAuthClientInput, PutExternalAppRequest, PutOAuthClientRequest } from './oauth-registry';
4
+ import type { ExternalAppDto, ExternalAppInput, OAuthClientDto, OAuthClientInput, PutExternalAppRequest, PutOAuthClientRequest } from './oauth-registry';
5
5
  import type { IssuePasskeyChallengeRequest, PasskeyChallenge, PasskeyCreationOptions, PasskeyDto, PasskeyRequestOptions, PasskeyResetResponse, RegisterPasskeyRequest, RemovePasskeyRequest, VerifiedPasskeyAssertion, VerifyPasskeyAssertionRequest } from './passkeys';
6
6
  import type { PasswordPolicyDto, SetPasswordPolicyRequest } from './password-policy';
7
7
  import type { ProvisionRequestedApiKeyRequest, RequestedApiKey, RequestedApiKeyInput, RequestedApiKeyResponse } from './requested-keys';
8
+ import type { ScimSettingsDto, ScimTokenIssuedDto } from './scim';
8
9
  /** A plain list response. */
9
10
  export interface ListResponse<T> {
10
11
  items: T[];
@@ -834,8 +835,6 @@ export interface IamAdminRpcContract {
834
835
  list: RpcProcedure<void, ListResponse<OAuthClientDto>>;
835
836
  put: RpcProcedure<PutOAuthClientRequest, OAuthClientDto>;
836
837
  delete: RpcProcedure<OAuthClientInput, OkResponse>;
837
- /** The deploy's one import of its client list, with the provisioning key; every later call writes nothing. */
838
- importOnce: RpcProcedure<ImportOAuthClientsRequest, ImportOAuthClientsResponse>;
839
838
  };
840
839
  policies: {
841
840
  list: RpcProcedure<AppInput, ListResponse<PolicyDto>>;
@@ -911,6 +910,17 @@ export interface IamAdminRpcContract {
911
910
  get: RpcProcedure<void, PasswordPolicyDto>;
912
911
  set: RpcProcedure<SetPasswordPolicyRequest, PasswordPolicyDto>;
913
912
  };
913
+ /**
914
+ * SCIM provisioning by the organization's identity provider (ADR-0091), an installation administrator's in a signed-in
915
+ * session. `rotateToken` creates the installation's one token or replaces it (the old one stops working at once) and
916
+ * answers the secret once; `revokeToken` removes it, after which every SCIM request is refused. Each writes
917
+ * `iam.scim.token.rotate` or `iam.scim.token.revoke`.
918
+ */
919
+ scim: {
920
+ get: RpcProcedure<void, ScimSettingsDto>;
921
+ rotateToken: RpcProcedure<void, ScimTokenIssuedDto>;
922
+ revokeToken: RpcProcedure<void, ScimSettingsDto>;
923
+ };
914
924
  /**
915
925
  * A person's second factor (TOTP), an installation administrator's (`iam.admin`) to read and to reset. The person
916
926
  * enrols at IAM's `SECOND_FACTOR_ENROL_PATH`, never here. A reset removes the authenticator and its recovery codes
@@ -966,3 +976,4 @@ export * from './oauth-registry';
966
976
  export * from './passkeys';
967
977
  export * from './password-policy';
968
978
  export * from './requested-keys';
979
+ export * from './scim';
@@ -1,9 +1,4 @@
1
1
  import type { OAuthClientProvider, OAuthIdentityRole } from './oauth';
2
- /**
3
- * IAM's refusal of a registry write before the deploy imported its client list (release N of ADR-0089), answered with
4
- * HTTP 409. The console and the CLI match it to say what to do instead of showing a generic conflict.
5
- */
6
- export declare const OAUTH_REGISTRY_NOT_IMPORTED: string;
7
2
  /** How many clients one external application has. */
8
3
  export declare const MAX_EXTERNAL_APP_CLIENTS = 16;
9
4
  /** One client of an external application: its client id, its exact redirect URIs and where IAM fetches its document. */
@@ -27,7 +22,7 @@ export interface PutExternalAppRequest {
27
22
  }
28
23
  export interface ExternalAppDto {
29
24
  app: string;
30
- /** Null for an application the deploy variable's import registered, which named none. */
25
+ /** Null for an application an earlier release's import of the deploy variable registered, which named none. */
31
26
  name: string | null;
32
27
  resource: string;
33
28
  /** Null when the application declares no roles. */
@@ -63,17 +58,3 @@ export interface PutOAuthClientRequest {
63
58
  export interface OAuthClientInput {
64
59
  clientId: string;
65
60
  }
66
- /**
67
- * The deploy variable's list, imported once (release N of ADR-0089): each entry in the shape `OAUTH_CONFIG.clients`
68
- * takes, an `OAuthManagedClient` with an optional `metadataUrl`. IAM checks every entry again.
69
- */
70
- export interface ImportOAuthClientsRequest {
71
- clients: unknown[];
72
- }
73
- export type ImportOAuthClientsResponse = {
74
- status: 'imported';
75
- externalApps: string[];
76
- oauthClients: string[];
77
- } | {
78
- status: 'already_imported';
79
- };
@@ -139,8 +139,11 @@ export type OAuthTokenRequest = {
139
139
  /** RFC 8628 §3.1, with every resource the grant is asked for (RFC 8707): each token names one of them. */
140
140
  export interface OAuthDeviceAuthorizationRequest {
141
141
  client_id: string;
142
+ /** Empty only for the agent client, which then asks for its default scope (ADR-0090 §2). */
142
143
  scope: string[];
143
144
  resources: string[];
145
+ /** The agent client's name for itself, shown to the person as the agent's own words; ignored for any other client. */
146
+ agent_label?: string;
144
147
  }
145
148
  /** RFC 8628 §3.2. */
146
149
  export interface OAuthDeviceAuthorizationResponse {
@@ -212,8 +215,9 @@ export declare function parseOAuthAuthorizationAttempt(value: unknown): OAuthAut
212
215
  export declare function parseOAuthAuthorizationRequest(value: unknown): OAuthAuthorizationRequest | null;
213
216
  export declare function parseOAuthTokenRequest(value: unknown): OAuthTokenRequest | null;
214
217
  /**
215
- * A device authorization request: its client, at least one scope and one to `MAX_OAUTH_DEVICE_RESOURCES` distinct
216
- * resources. `resource` is the one parameter that may repeat (RFC 8707 §2), so the caller collects it into a list.
218
+ * A device authorization request: its client, at least one scope (the agent client may name none) and one to
219
+ * `MAX_OAUTH_DEVICE_RESOURCES` distinct resources. `resource` is the one parameter that may repeat (RFC 8707 §2), so the
220
+ * caller collects it into a list.
217
221
  */
218
222
  export declare function parseOAuthDeviceAuthorizationRequest(value: {
219
223
  fields: Record<string, string>;
@@ -0,0 +1,15 @@
1
+ /** The installation's SCIM provisioning as the console shows it. */
2
+ export interface ScimSettingsDto {
3
+ /** The tenant URL an identity provider is configured with: IAM's origin and `/scim/v2`. */
4
+ endpoint: string;
5
+ /** Whether a token exists; without one IAM refuses every SCIM request. */
6
+ configured: boolean;
7
+ /** When the current token was created, in epoch seconds; null without one. */
8
+ createdAt: number | null;
9
+ }
10
+ /** A token just created: the secret is in this answer and nowhere else, ever again. */
11
+ export interface ScimTokenIssuedDto extends ScimSettingsDto {
12
+ configured: true;
13
+ createdAt: number;
14
+ token: string;
15
+ }