@fabrika/iam 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",
3
- "version": "0.9.0-dev.34",
3
+ "version": "0.9.0-dev.35",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/contember/fabrika-platform.git",
@@ -56,16 +56,16 @@
56
56
  "prune:auth-log": "bun src/node/prune.ts"
57
57
  },
58
58
  "dependencies": {
59
- "@fabrika/app": "0.9.0-dev.34",
60
- "@fabrika/auth": "0.9.0-dev.34",
61
- "@fabrika/auth-core": "0.9.0-dev.34",
62
- "@fabrika/control-contract": "0.9.0-dev.34",
63
- "@fabrika/email": "0.9.0-dev.34",
64
- "@fabrika/iam-contract": "0.9.0-dev.34",
65
- "@fabrika/platform": "0.9.0-dev.34",
66
- "@fabrika/platform-node": "0.9.0-dev.34",
67
- "@fabrika/provider-cloudflare": "0.9.0-dev.34",
68
- "@fabrika/proxy-core": "0.9.0-dev.34",
59
+ "@fabrika/app": "0.9.0-dev.35",
60
+ "@fabrika/auth": "0.9.0-dev.35",
61
+ "@fabrika/auth-core": "0.9.0-dev.35",
62
+ "@fabrika/control-contract": "0.9.0-dev.35",
63
+ "@fabrika/email": "0.9.0-dev.35",
64
+ "@fabrika/iam-contract": "0.9.0-dev.35",
65
+ "@fabrika/platform": "0.9.0-dev.35",
66
+ "@fabrika/platform-node": "0.9.0-dev.35",
67
+ "@fabrika/provider-cloudflare": "0.9.0-dev.35",
68
+ "@fabrika/proxy-core": "0.9.0-dev.35",
69
69
  "jose": "^5.9.0",
70
70
  "uqr": "^0.1.3",
71
71
  "zod": "^3.25.76"
@@ -22,6 +22,7 @@ import { parseOAuthConfig } from '../oauth-config'
22
22
  import { parseOidcSessionSeconds } from '../oidc-session'
23
23
  import { BUN_PBKDF2_COST } from '../password-crypto'
24
24
  import { parseRetention } from '../retention'
25
+ import { parseAdminAudiences, platformAudiencesFor } from '../services'
25
26
 
26
27
  /** Config that exists ONLY off Workers — the process's own knobs, not part of the service's `Env`. */
27
28
  export interface ProcessConfig {
@@ -102,7 +103,7 @@ export async function createRuntime(source: Record<string, string | undefined> =
102
103
  const controlUrl = httpOrigin(source, 'FABRIKA_CONTROL_URL')
103
104
 
104
105
  // Parsed here as well as per request in `buildServices`, for the same readiness-probe reason as above.
105
- parseOAuthConfig(source['FABRIKA_IAM_OAUTH_CONFIG'])
106
+ parseOAuthConfig(source['FABRIKA_IAM_OAUTH_CONFIG'], platformAudiencesFor(parseAdminAudiences(source['FABRIKA_IAM_ADMIN_AUDIENCES'])))
106
107
  const authLogRetentionDays = source['FABRIKA_IAM_AUTH_LOG_RETENTION_DAYS']
107
108
  const auditRetentionDays = source['FABRIKA_IAM_AUDIT_RETENTION_DAYS']
108
109
  parseRetention(
@@ -15,15 +15,16 @@ export interface OAuthConfig {
15
15
  const MAX_CLIENTS = 16
16
16
  const MAX_RESOURCES = 32
17
17
  const CONFIG_KEYS = ['clients', 'resources']
18
- const CLIENT_KEYS = ['provider', 'clientId', 'redirectUris', 'metadataUrl']
18
+ const CLIENT_KEYS = ['provider', 'clientId', 'redirectUris', 'metadataUrl', 'identity']
19
19
  const RESOURCE_KEYS = ['app', 'resource', 'defaultScopes', 'scopeGrants', 'client']
20
20
 
21
21
  /**
22
22
  * Parse `OAUTH_CONFIG`. Absent or empty disables OAuth; anything malformed THROWS, so a typo fails the boot instead of
23
23
  * quietly serving fewer clients or scopes than the operator wrote. Unknown keys are refused for the same reason.
24
- * `clients` may be empty: the command-line client is IAM's own and never listed.
24
+ * `clients` may be empty: the command-line client is IAM's own and never listed. A client's identity resource names
25
+ * neither a registered resource nor a `platformAudiences` app, so its token is never one an installation service accepts.
25
26
  */
26
- export function parseOAuthConfig(raw: string | undefined): OAuthConfig | null {
27
+ export function parseOAuthConfig(raw: string | undefined, platformAudiences: ReadonlySet<string>): OAuthConfig | null {
27
28
  if (raw === undefined || raw.trim() === '') return null
28
29
  const value = parseJsonOrNull(raw)
29
30
  const rawClients = prop(value, 'clients')
@@ -55,6 +56,14 @@ export function parseOAuthConfig(raw: string | undefined): OAuthConfig | null {
55
56
  }
56
57
  resources.push(resource)
57
58
  }
59
+ for (const [index, { identity }] of clients.entries()) {
60
+ if (
61
+ identity !== undefined
62
+ && (platformAudiences.has(identity.app) || resources.some((entry) => entry.resource === identity.resource || entry.app === identity.app))
63
+ ) {
64
+ throw new Error(`OAUTH_CONFIG.clients[${index}].identity names an installation service's app or resource`)
65
+ }
66
+ }
58
67
  return { clients, resources }
59
68
  }
60
69
 
@@ -1,4 +1,5 @@
1
1
  import { DEFAULT_LOCALE, narrowPermissions, type PermissionEntry } from '@fabrika/auth-core'
2
+ import { CONTROL_APP_ID, CONTROL_CLI_RESOURCES } from '@fabrika/control-contract'
2
3
  import { isOAuthDeviceGrantLifetime, OAUTH_DEVICE_GRANT_LIFETIMES_SECONDS, type OAuthResourceDto } from '@fabrika/iam-contract'
3
4
  import { sessionEndsAt } from './auth'
4
5
  import { readForm, redirectHeaders, sameOrigin } from './auth/http'
@@ -115,7 +116,7 @@ async function consentPage(
115
116
  const authority = await resolveAuthorityAt(services, principal, attempt.app)
116
117
  const sections = resources.map((resource) => {
117
118
  const permissions = narrowPermissions(authority.permissions, scopeCeiling(resource, request.scopes) ?? [])
118
- return `<h2><code>${escapeHtml(resource.resource)}</code></h2>${permissionList(permissions)}`
119
+ return `<h2>${escapeHtml(resourceLabel(resource))}</h2><p class="uri">${escapeHtml(resource.resource)}</p>${permissionList(permissions)}`
119
120
  })
120
121
  const unbounded = request.scopes.filter((token) => resources.some((resource) => isUnbounded(resource, token)))
121
122
  const warning = unbounded.length === 0
@@ -124,7 +125,7 @@ async function consentPage(
124
125
  unbounded.map((token) => `<code>${escapeHtml(token)}</code>`).join(', ')
125
126
  } is not limited to one scope value: it holds its actions everywhere you hold them.</p>`
126
127
  const lifetimes = OAUTH_DEVICE_GRANT_LIFETIMES_SECONDS.map((seconds, index) =>
127
- `<label><input type="radio" name="lifetime" value="${seconds}"${index === 0 ? ' checked' : ''}> ${LIFETIME_LABELS[seconds]}</label>`
128
+ `<label class="choice"><input type="radio" name="lifetime" value="${seconds}"${index === 0 ? ' checked' : ''}> ${LIFETIME_LABELS[seconds]}</label>`
128
129
  )
129
130
  return page(
130
131
  services,
@@ -134,7 +135,7 @@ async function consentPage(
134
135
  <p>A device asks to act as you in <strong>${escapeHtml(attempt.app)}</strong>. It started this request at
135
136
  <strong>${new Date(attempt.created_at * 1000).toISOString()}</strong> with the code <code>${escapeHtml(formatUserCode(userCode))}</code>.
136
137
  Allow it only if you started it yourself.</p>
137
- <p>Scopes: <code>${escapeHtml(request.scopes.join(' '))}</code></p>
138
+ <p>Scopes: ${request.scopes.map((token) => `<code>${escapeHtml(token)}</code>`).join(' ')}</p>
138
139
  ${warning}
139
140
  <p>At most these permissions, and only while you hold them yourself:</p>
140
141
  ${sections.join('')}
@@ -142,11 +143,21 @@ async function consentPage(
142
143
  <input type="hidden" name="user_code" value="${escapeHtml(formatUserCode(userCode))}">
143
144
  <fieldset><legend>Access lasts</legend>${lifetimes.join('')}</fieldset>
144
145
  <p>Access also ends when this sign-in ends or when it is revoked.</p>
145
- <button name="decision" value="approve">Allow</button>
146
- <button name="decision" value="deny">Deny</button></form>`,
146
+ <div class="actions"><button name="decision" value="approve">Allow</button>
147
+ <button name="decision" value="deny">Deny</button></div></form>`,
147
148
  )
148
149
  }
149
150
 
151
+ /**
152
+ * What a person reads a resource as: the name the console gives its command-line resource (the device grant serves
153
+ * only those), else the resource's path, which tells two resources of one app apart. The full URI stays under it.
154
+ */
155
+ function resourceLabel(resource: OAuthResourceDto): string {
156
+ const path = new URL(resource.resource).pathname
157
+ const known = resource.app === CONTROL_APP_ID ? CONTROL_CLI_RESOURCES.find((entry) => entry.path === path) : undefined
158
+ return known?.label ?? path
159
+ }
160
+
150
161
  /** A scope whose actions no parameter narrows and at least one of which names no scope of its own. */
151
162
  function isUnbounded(resource: OAuthResourceDto, token: string): boolean {
152
163
  const grant = resource.scopeGrants.find((entry) => entry.scope === token)
@@ -157,9 +168,9 @@ function permissionList(permissions: readonly PermissionEntry[]): string {
157
168
  if (permissions.length === 0) return '<p>None: you hold none of these permissions yourself.</p>'
158
169
  const items = permissions.map((permission) => {
159
170
  const scope = permission.scope == null ? 'everywhere' : `${permission.scope.type} ${permission.scope.value}`
160
- return `<li><code>${escapeHtml(permission.action)}</code> — ${escapeHtml(scope)}</li>`
171
+ return `<li><code>${escapeHtml(permission.action)}</code> <span>${escapeHtml(scope)}</span></li>`
161
172
  })
162
- return `<ul>${items.join('')}</ul>`
173
+ return `<ul class="rows">${items.join('')}</ul>`
163
174
  }
164
175
 
165
176
  async function page(services: Services, title: string, content: string, status = 200): Promise<Response> {
package/src/oauth-http.ts CHANGED
@@ -1,17 +1,18 @@
1
- import { DEFAULT_LOCALE } from '@fabrika/auth-core'
1
+ import { DEFAULT_LOCALE, type KeyGrant } from '@fabrika/auth-core'
2
2
  import {
3
3
  OAUTH_CLIENT_ASSERTION_ALGORITHMS,
4
4
  OAUTH_DEVICE_CODE_GRANT_TYPE,
5
5
  type OAuthAuthorizationRequest,
6
6
  type OAuthAuthorizationServerMetadata,
7
7
  type OAuthClientCredential,
8
- type OAuthResourceDto,
8
+ type OAuthIdentityResource,
9
9
  parseOAuthAuthorizationAttempt,
10
10
  parseOAuthClientCredential,
11
11
  parseOAuthDeviceAuthorizationRequest,
12
12
  parseOAuthRevocationRequest,
13
13
  parseOAuthTokenRequest,
14
14
  resolveOAuthAuthorizationScopes,
15
+ resolveOAuthIdentityScopes,
15
16
  } from '@fabrika/iam-contract'
16
17
  import { decodeJwt } from 'jose'
17
18
  import { readForm, redirectHeaders, sameOrigin } from './auth/http'
@@ -20,7 +21,16 @@ import { principalStatus } from './db'
20
21
  import type { Env } from './env'
21
22
  import { escapeHtml } from './html'
22
23
  import { installationBrand } from './installation-brand'
23
- import { establishClient, exchangeOAuthToken, grantAuthorization, type ManagedClient, revokeOAuthToken, scopeCeiling, servesClient } from './oauth'
24
+ import {
25
+ type AuthorizationTarget,
26
+ establishClient,
27
+ exchangeOAuthToken,
28
+ grantAuthorization,
29
+ type ManagedClient,
30
+ revokeOAuthToken,
31
+ scopeCeiling,
32
+ servesClient,
33
+ } from './oauth'
24
34
  import { authenticateOAuthClient, authenticateRevokingClient } from './oauth-client-auth'
25
35
  import type { OAuthConfig } from './oauth-config'
26
36
  import { OAUTH_DEVICE_PATH, redeemDeviceCode, startDeviceAuthorization } from './oauth-device'
@@ -95,7 +105,7 @@ function authorizationServerMetadata(issuer: string): Response {
95
105
  type AuthorizationCheck =
96
106
  | { kind: 'refused'; message: string }
97
107
  | { kind: 'redirect'; response: Response }
98
- | { kind: 'valid'; request: OAuthAuthorizationRequest; client: ManagedClient; resource: OAuthResourceDto; scopes: string[] }
108
+ | { kind: 'valid'; request: OAuthAuthorizationRequest; client: ManagedClient; resource: AuthorizationTarget; scopes: string[]; ceiling: KeyGrant[] }
99
109
 
100
110
  /**
101
111
  * Validate an authorization request in the order RFC 6749 §4.1.2.1 requires: until the client and its
@@ -108,12 +118,28 @@ async function checkAuthorization(issuer: string, config: OAuthConfig, input: Re
108
118
  const client = await establishClient(config, coordinates.client_id, coordinates.redirect_uri)
109
119
  if (client === null) return { kind: 'refused', message: 'The client or its redirect URI is not registered.' }
110
120
  if (attempt.kind === 'invalid_scope') return { kind: 'redirect', response: clientRedirect(issuer, coordinates, { error: 'invalid_scope' }) }
121
+ const identity = client.registration.identity
122
+ if (identity !== undefined) return checkIdentityAuthorization(issuer, attempt.request, client, identity)
111
123
  // The command-line client's resources are served through the device grant only, never to a managed client.
112
124
  const resource = config.resources.find((entry) => entry.resource === coordinates.resource && servesClient(entry, false))
113
125
  if (resource === undefined) return { kind: 'redirect', response: clientRedirect(issuer, coordinates, { error: 'invalid_target' }) }
114
126
  const scopes = resolveOAuthAuthorizationScopes(attempt.request.scope, resource)
115
- if (scopes === null) return { kind: 'redirect', response: clientRedirect(issuer, coordinates, { error: 'invalid_scope' }) }
116
- return { kind: 'valid', request: attempt.request, client, resource, scopes }
127
+ const ceiling = scopes === null ? null : scopeCeiling(resource, scopes)
128
+ if (scopes === null || ceiling === null) return { kind: 'redirect', response: clientRedirect(issuer, coordinates, { error: 'invalid_scope' }) }
129
+ return { kind: 'valid', request: attempt.request, client, resource, scopes, ceiling }
130
+ }
131
+
132
+ /** An identity-only client is served its own resource alone, with the `identity` scope and no permission. */
133
+ function checkIdentityAuthorization(
134
+ issuer: string,
135
+ request: OAuthAuthorizationRequest,
136
+ client: ManagedClient,
137
+ identity: OAuthIdentityResource,
138
+ ): AuthorizationCheck {
139
+ if (request.resource !== identity.resource) return { kind: 'redirect', response: clientRedirect(issuer, request, { error: 'invalid_target' }) }
140
+ const scopes = resolveOAuthIdentityScopes(request.scope)
141
+ if (scopes === null) return { kind: 'redirect', response: clientRedirect(issuer, request, { error: 'invalid_scope' }) }
142
+ return { kind: 'valid', request, client, resource: identity, scopes, ceiling: [] }
117
143
  }
118
144
 
119
145
  async function showConsent(request: Request, services: Services, config: OAuthConfig): Promise<Response> {
@@ -228,12 +254,19 @@ function withAssertedClientId(fields: Record<string, string> | null, credential:
228
254
  }
229
255
 
230
256
  async function consentPage(services: Services, check: Extract<AuthorizationCheck, { kind: 'valid' }>, signedInAs: string): Promise<Response> {
231
- const { request, client, resource, scopes } = check
257
+ const { request, client, resource, scopes, ceiling } = check
232
258
  const clientName = client.metadata.client_name ?? client.registration.clientId
233
- const permissions = (scopeCeiling(resource, scopes) ?? []).map((permission) => {
259
+ const permissions = ceiling.map((permission) => {
234
260
  const scope = permission.scope == null ? 'everywhere' : `${permission.scope.type} ${permission.scope.value}`
235
261
  return `<li><code>${escapeHtml(permission.action)}</code> — ${escapeHtml(scope)}</li>`
236
262
  })
263
+ const asks = client.registration.identity === undefined
264
+ ? `<p><strong>${escapeHtml(clientName)}</strong> asks to act as you in <strong>${escapeHtml(resource.app)}</strong>.</p>`
265
+ : `<p><strong>${escapeHtml(clientName)}</strong> asks to know who you are. It receives your account and name, and no permission.</p>`
266
+ const grants = client.registration.identity === undefined
267
+ ? `<p>At most these permissions, and only those you hold yourself:</p>
268
+ <ul>${permissions.join('')}</ul>`
269
+ : ''
237
270
  const fields: [string, string | undefined][] = [
238
271
  ['response_type', request.response_type],
239
272
  ['client_id', request.client_id],
@@ -251,12 +284,11 @@ async function consentPage(services: Services, check: Extract<AuthorizationCheck
251
284
  title: 'Authorize application',
252
285
  content: `<h1>Authorize ${escapeHtml(clientName)}</h1>
253
286
  <p>Signed in as <strong>${escapeHtml(signedInAs)}</strong>.</p>
254
- <p><strong>${escapeHtml(clientName)}</strong> asks to act as you in <strong>${escapeHtml(resource.app)}</strong>.</p>
287
+ ${asks}
255
288
  <p>Client: <code>${escapeHtml(client.registration.clientId)}</code></p>
256
289
  <p>Resource: <code>${escapeHtml(resource.resource)}</code></p>
257
290
  <p>Scopes: <code>${escapeHtml(scopes.join(' '))}</code></p>
258
- <p>At most these permissions, and only those you hold yourself:</p>
259
- <ul>${permissions.join('')}</ul>
291
+ ${grants}
260
292
  <p>Access ends when this sign-in ends or when it is revoked.</p>
261
293
  <form method="post" action="${AUTHORIZE_PATH}">${hidden.join('')}
262
294
  <button name="decision" value="approve">Allow</button>
package/src/oauth.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  } from '@fabrika/auth-core'
10
10
  import {
11
11
  OAUTH_DEVICE_CODE_GRANT_TYPE,
12
+ OAUTH_IDENTITY_SCOPE,
12
13
  type OAuthAuthorizationRequest,
13
14
  type OAuthClientMetadataDocument,
14
15
  type OAuthResourceDto,
@@ -82,10 +83,13 @@ export async function establishClient(config: OAuthConfig, clientId: string, red
82
83
  return { kind: 'managed', registration, metadata }
83
84
  }
84
85
 
86
+ /** What a consent grants: a registered resource, or an identity-only client's own resource. */
87
+ export type AuthorizationTarget = Pick<OAuthResourceDto, 'app' | 'resource'>
88
+
85
89
  /** Record the consent and return the plaintext authorization code — the only time it exists. */
86
90
  export async function grantAuthorization(
87
91
  services: Services,
88
- input: { request: OAuthAuthorizationRequest; resource: OAuthResourceDto; scopes: string[]; session: SessionRow; requestId: string },
92
+ input: { request: OAuthAuthorizationRequest; resource: AuthorizationTarget; scopes: string[]; session: SessionRow; requestId: string },
89
93
  ): Promise<string> {
90
94
  const now = unixNow()
91
95
  const code = generateToken()
@@ -294,13 +298,8 @@ export async function grantAuthority(
294
298
  ): Promise<{ principal: PrincipalRow; scopes: string[]; permissions: PermissionEntry[]; expiresAt: number | null } | null> {
295
299
  const config = services.config.oauth
296
300
  if (config === null || grant.revoked_at !== null || grant.expires_at <= now || !grantResources(grant).includes(resourceUri)) return null
297
- const resource = config.resources.find((entry) =>
298
- entry.resource === resourceUri && entry.app === grant.app && servesClient(entry, grant.client_id === OAUTH_CLI_CLIENT_ID)
299
- )
300
- const clientKnown = grant.client_id === OAUTH_CLI_CLIENT_ID || config.clients.some((client) => client.clientId === grant.client_id)
301
- if (resource === undefined || !clientKnown) return null
302
301
  const scopes = parseOAuthScopes(parseJsonOrNull(grant.scopes))
303
- const ceiling = scopes === null ? null : scopeCeiling(resource, scopes)
302
+ const ceiling = scopes === null ? null : grantCeiling(config, grant, resourceUri, scopes)
304
303
  if (scopes === null || ceiling === null) return null
305
304
  const session = await services.repositories.sessions.getActiveSessionById(grant.session_id)
306
305
  if (session === null || session.app !== null || session.principal_id !== grant.principal_id || !sessionUsable(session, services.config, now)) {
@@ -308,13 +307,43 @@ export async function grantAuthority(
308
307
  }
309
308
  const principal = await services.repositories.principals.getPrincipalById(grant.principal_id)
310
309
  if (principal === null || principal.type !== 'user' || principalStatus(principal) !== 'active') return null
310
+ // No grant is read for an identity resource: its token names the person and carries no permission.
311
+ if (ceiling.kind === 'identity') return { principal, scopes, permissions: [], expiresAt: sessionEndsAt(session, services.config) }
311
312
  const live = await resolveAuthorityAt(services, principal, grant.app)
312
- const permissions = narrowPermissions(live.permissions, ceiling)
313
+ const permissions = narrowPermissions(live.permissions, ceiling.permissions)
313
314
  // A refreshed token ends with its login too: an OIDC login issued before the cap stores a later expiry than its end.
314
315
  const expiresAt = Math.min(authorityDeadline(live, permissions, now) ?? Number.POSITIVE_INFINITY, sessionEndsAt(session, services.config))
315
316
  return { principal, scopes, permissions, expiresAt }
316
317
  }
317
318
 
319
+ /**
320
+ * What a grant's token may carry at `resourceUri` under the current configuration, or null when its client or resource
321
+ * is no longer configured for it. An identity-only client is served its own resource alone, so a grant it holds for
322
+ * any other one (given before it was bound) mints nothing, and a grant for an identity resource carries no permission.
323
+ */
324
+ function grantCeiling(
325
+ config: OAuthConfig,
326
+ grant: OAuthGrantRow,
327
+ resourceUri: string,
328
+ scopes: readonly string[],
329
+ ): { kind: 'identity' } | { kind: 'scoped'; permissions: KeyGrant[] } | null {
330
+ const cli = grant.client_id === OAUTH_CLI_CLIENT_ID
331
+ const client = config.clients.find((entry) => entry.clientId === grant.client_id)
332
+ if (!cli && client === undefined) return null
333
+ const identity = client?.identity
334
+ if (identity !== undefined) {
335
+ const matches = identity.resource === resourceUri && identity.app === grant.app && sameScopes(scopes, [OAUTH_IDENTITY_SCOPE])
336
+ return matches ? { kind: 'identity' } : null
337
+ }
338
+ const resource = config.resources.find((entry) => entry.resource === resourceUri && entry.app === grant.app && servesClient(entry, cli))
339
+ const permissions = resource === undefined ? null : scopeCeiling(resource, scopes)
340
+ return permissions === null ? null : { kind: 'scoped', permissions }
341
+ }
342
+
343
+ function sameScopes(scopes: readonly string[], expected: readonly string[]): boolean {
344
+ return scopes.length === expected.length && scopes.every((scope, index) => scope === expected[index])
345
+ }
346
+
318
347
  /** The union of the scopes' grants, or null when a scope is no longer configured. */
319
348
  export function scopeCeiling(resource: OAuthResourceDto, scopes: readonly string[]): KeyGrant[] | null {
320
349
  const ceiling: KeyGrant[] = []
package/src/services.ts CHANGED
@@ -97,7 +97,7 @@ const APP_ID = /^[a-z0-9][a-z0-9-]*$/
97
97
  * empty = no JWT may administer. A malformed entry is REFUSED rather than skipped: an entry no `aud`
98
98
  * can ever equal would otherwise read as a registry while admitting nobody.
99
99
  */
100
- function parseAdminAudiences(raw: string | undefined): ReadonlySet<string> {
100
+ export function parseAdminAudiences(raw: string | undefined): ReadonlySet<string> {
101
101
  if (raw === undefined) {
102
102
  return DEFAULT_ADMIN_AUDIENCES
103
103
  }
@@ -152,7 +152,7 @@ export function buildServices(env: Env): Services {
152
152
  oidc: { enabled: oidcEnabled, sessionCapSeconds: parseOidcSessionSeconds(env.OIDC_SESSION_HOURS) },
153
153
  password: { enabled: passwordEnabled, minLengthFloor: passwordMinLengthFloor(passwordCost) },
154
154
  },
155
- oauth: parseOAuthConfig(env.OAUTH_CONFIG),
155
+ oauth: parseOAuthConfig(env.OAUTH_CONFIG, platformAudiencesFor(adminAudiences)),
156
156
  retention: parseRetention({ authLogDays: env.AUTH_LOG_RETENTION_DAYS, auditDays: env.AUDIT_RETENTION_DAYS }),
157
157
  issuer: env.ISSUER,
158
158
  },
@@ -11,6 +11,7 @@ export interface OAuthConfig {
11
11
  /**
12
12
  * Parse `OAUTH_CONFIG`. Absent or empty disables OAuth; anything malformed THROWS, so a typo fails the boot instead of
13
13
  * quietly serving fewer clients or scopes than the operator wrote. Unknown keys are refused for the same reason.
14
- * `clients` may be empty: the command-line client is IAM's own and never listed.
14
+ * `clients` may be empty: the command-line client is IAM's own and never listed. A client's identity resource names
15
+ * neither a registered resource nor a `platformAudiences` app, so its token is never one an installation service accepts.
15
16
  */
16
- export declare function parseOAuthConfig(raw: string | undefined): OAuthConfig | null;
17
+ export declare function parseOAuthConfig(raw: string | undefined, platformAudiences: ReadonlySet<string>): OAuthConfig | null;
@@ -34,10 +34,12 @@ export declare function storedResourceList(text: string): string[] | null;
34
34
  * `redirect_uri`. An unregistered client id is refused before any metadata fetch.
35
35
  */
36
36
  export declare function establishClient(config: OAuthConfig, clientId: string, redirectUri: string): Promise<ManagedClient | null>;
37
+ /** What a consent grants: a registered resource, or an identity-only client's own resource. */
38
+ export type AuthorizationTarget = Pick<OAuthResourceDto, 'app' | 'resource'>;
37
39
  /** Record the consent and return the plaintext authorization code — the only time it exists. */
38
40
  export declare function grantAuthorization(services: Services, input: {
39
41
  request: OAuthAuthorizationRequest;
40
- resource: OAuthResourceDto;
42
+ resource: AuthorizationTarget;
41
43
  scopes: string[];
42
44
  session: SessionRow;
43
45
  requestId: string;
@@ -73,4 +73,10 @@ export declare const DEFAULT_ADMIN_AUDIENCES: ReadonlySet<string>;
73
73
  export declare const DEFAULT_PLATFORM_AUDIENCES: ReadonlySet<string>;
74
74
  /** An admin audience is a console gateway, so it is a platform service too, whatever it is named. */
75
75
  export declare function platformAudiencesFor(adminAudiences: ReadonlySet<string>): ReadonlySet<string>;
76
+ /**
77
+ * Parse `ADMIN_AUDIENCES` (comma-separated app ids). Unset = `DEFAULT_ADMIN_AUDIENCES`; explicitly
78
+ * empty = no JWT may administer. A malformed entry is REFUSED rather than skipped: an entry no `aud`
79
+ * can ever equal would otherwise read as a registry while admitting nobody.
80
+ */
81
+ export declare function parseAdminAudiences(raw: string | undefined): ReadonlySet<string>;
76
82
  export declare function buildServices(env: Env): Services;