@fabrika/auth-core 0.9.0-dev.34 → 0.9.0-dev.36
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 +1 -1
- package/src/token.ts +28 -1
- package/types/src/token.d.ts +9 -0
package/package.json
CHANGED
package/src/token.ts
CHANGED
|
@@ -183,6 +183,11 @@ export interface OAuthTokenClaims {
|
|
|
183
183
|
grantId: string
|
|
184
184
|
/** Unique token id, fresh on every mint. */
|
|
185
185
|
tokenId: string
|
|
186
|
+
/**
|
|
187
|
+
* The keys of the roles the person holds at an external application that declares roles; absent on every other
|
|
188
|
+
* token. The application decides what each role allows; IAM grants it and names it here.
|
|
189
|
+
*/
|
|
190
|
+
roles?: string[]
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
/** Which tokens a verifier accepts: native app tokens, or OAuth tokens minted for one resource of one app. */
|
|
@@ -252,6 +257,10 @@ export interface ResourceAccessTokenParams {
|
|
|
252
257
|
scopes: string[]
|
|
253
258
|
grantId: string
|
|
254
259
|
tokenId: string
|
|
260
|
+
/** The person's normalized mailbox; an identity resource's token carries it. */
|
|
261
|
+
email?: string
|
|
262
|
+
/** The roles the person holds at an external application that declares roles (`OAuthTokenClaims.roles`). */
|
|
263
|
+
roles?: string[]
|
|
255
264
|
}
|
|
256
265
|
|
|
257
266
|
/**
|
|
@@ -274,6 +283,8 @@ export function buildResourceAccessClaims(params: ResourceAccessTokenParams): Re
|
|
|
274
283
|
scope: params.scopes.join(' '),
|
|
275
284
|
grant: params.grantId,
|
|
276
285
|
jti: params.tokenId,
|
|
286
|
+
...(params.email === undefined ? {} : { email: params.email }),
|
|
287
|
+
...(params.roles === undefined ? {} : { roles: params.roles }),
|
|
277
288
|
}
|
|
278
289
|
if (parseAccessClaims(payload)?.oauth === undefined) throw new Error('Invalid resource access token claims')
|
|
279
290
|
return payload
|
|
@@ -523,7 +534,23 @@ function parseOAuthClaims(payload: unknown): OAuthTokenClaims | null | undefined
|
|
|
523
534
|
) {
|
|
524
535
|
return undefined
|
|
525
536
|
}
|
|
526
|
-
|
|
537
|
+
const roles = parseTokenRoles(prop(payload, 'roles'))
|
|
538
|
+
if (roles === undefined) return undefined
|
|
539
|
+
return roles === null ? { app, clientId, scopes, grantId, tokenId } : { app, clientId, scopes, grantId, tokenId, roles }
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const TOKEN_ROLE = /^[a-z0-9][a-z0-9-]{0,62}$/
|
|
543
|
+
|
|
544
|
+
/** Absent → null; distinct role keys → them; anything else → undefined. */
|
|
545
|
+
function parseTokenRoles(value: unknown): string[] | null | undefined {
|
|
546
|
+
if (value === undefined) return null
|
|
547
|
+
if (!Array.isArray(value) || value.length > 32) return undefined
|
|
548
|
+
const roles: string[] = []
|
|
549
|
+
for (const role of value) {
|
|
550
|
+
if (typeof role !== 'string' || !TOKEN_ROLE.test(role) || roles.includes(role)) return undefined
|
|
551
|
+
roles.push(role)
|
|
552
|
+
}
|
|
553
|
+
return roles
|
|
527
554
|
}
|
|
528
555
|
|
|
529
556
|
/**
|
package/types/src/token.d.ts
CHANGED
|
@@ -156,6 +156,11 @@ export interface OAuthTokenClaims {
|
|
|
156
156
|
grantId: string;
|
|
157
157
|
/** Unique token id, fresh on every mint. */
|
|
158
158
|
tokenId: string;
|
|
159
|
+
/**
|
|
160
|
+
* The keys of the roles the person holds at an external application that declares roles; absent on every other
|
|
161
|
+
* token. The application decides what each role allows; IAM grants it and names it here.
|
|
162
|
+
*/
|
|
163
|
+
roles?: string[];
|
|
159
164
|
}
|
|
160
165
|
/** Which tokens a verifier accepts: native app tokens, or OAuth tokens minted for one resource of one app. */
|
|
161
166
|
export type TokenAudienceProfile = {
|
|
@@ -218,6 +223,10 @@ export interface ResourceAccessTokenParams {
|
|
|
218
223
|
scopes: string[];
|
|
219
224
|
grantId: string;
|
|
220
225
|
tokenId: string;
|
|
226
|
+
/** The person's normalized mailbox; an identity resource's token carries it. */
|
|
227
|
+
email?: string;
|
|
228
|
+
/** The roles the person holds at an external application that declares roles (`OAuthTokenClaims.roles`). */
|
|
229
|
+
roles?: string[];
|
|
221
230
|
}
|
|
222
231
|
/**
|
|
223
232
|
* Assemble an OAuth resource access token. Always a user principal. The wire carries the standard
|