@schemavaults/jwt 0.11.12 → 0.13.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
-
import type
|
|
2
|
+
import { type UserData } from "@schemavaults/auth-common";
|
|
3
3
|
import type { I_JWT_Keys } from "./jwt_keys";
|
|
4
4
|
/**
|
|
5
5
|
* OIDC id_token lifetime in seconds. Deliberately short-lived: the
|
|
@@ -15,7 +15,9 @@ export interface GenerateIdTokenOptions {
|
|
|
15
15
|
nonce?: string | null;
|
|
16
16
|
/**
|
|
17
17
|
* Granted OIDC scopes; `email`/`email_verified` claims are only
|
|
18
|
-
* included when the `email` scope was granted
|
|
18
|
+
* included when the `email` scope was granted, and the profile name
|
|
19
|
+
* claims (`name`, `given_name`, `middle_name`, `family_name`,
|
|
20
|
+
* `preferred_username`) only when the `profile` scope was granted.
|
|
19
21
|
*/
|
|
20
22
|
scopes: readonly string[];
|
|
21
23
|
/**
|
|
@@ -26,6 +28,13 @@ export interface GenerateIdTokenOptions {
|
|
|
26
28
|
jwt_keys: I_JWT_Keys;
|
|
27
29
|
environment: SchemaVaultsAppEnvironment;
|
|
28
30
|
auth_server_url?: string;
|
|
31
|
+
/**
|
|
32
|
+
* This deployment's own app id (SCHEMAVAULTS_AUTH_SERVER_APP_ID) —
|
|
33
|
+
* prefixes the `sub` claim as `<auth_server_app_id>|<uid>` (see
|
|
34
|
+
* formatOidcSubClaim in @schemavaults/auth-common). Server-side
|
|
35
|
+
* callers may rely on the env-resolved default.
|
|
36
|
+
*/
|
|
37
|
+
auth_server_app_id?: string;
|
|
29
38
|
}
|
|
30
39
|
export interface GeneratedIdToken {
|
|
31
40
|
id_token: string;
|
|
@@ -39,5 +48,5 @@ export interface GeneratedIdToken {
|
|
|
39
48
|
* platform convention (`<keyset_id>-verification`) so it matches the
|
|
40
49
|
* keys served by the jwks_uri.
|
|
41
50
|
*/
|
|
42
|
-
export declare function generateIdToken({ user, client_id, nonce, scopes, jwt_keys, environment, auth_server_url, }: GenerateIdTokenOptions): Promise<GeneratedIdToken>;
|
|
51
|
+
export declare function generateIdToken({ user, client_id, nonce, scopes, jwt_keys, environment, auth_server_url, auth_server_app_id, }: GenerateIdTokenOptions): Promise<GeneratedIdToken>;
|
|
43
52
|
export default generateIdToken;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SignJWT } from "jose";
|
|
2
|
-
import { getAuthServerUrl, } from "@schemavaults/app-definitions";
|
|
2
|
+
import { getAuthServerAppId, getAuthServerUrl, } from "@schemavaults/app-definitions";
|
|
3
|
+
import { buildOidcProfileClaims, formatOidcSubClaim, } from "@schemavaults/auth-common";
|
|
3
4
|
import signAndVerifyAlg from "./sign_verify_alg";
|
|
4
5
|
import isValidUuid from "../utils/isValidUuid";
|
|
5
6
|
/**
|
|
@@ -15,7 +16,7 @@ export const ID_TOKEN_EXPIRY = 3600;
|
|
|
15
16
|
* platform convention (`<keyset_id>-verification`) so it matches the
|
|
16
17
|
* keys served by the jwks_uri.
|
|
17
18
|
*/
|
|
18
|
-
export async function generateIdToken({ user, client_id, nonce, scopes, jwt_keys, environment, auth_server_url = getAuthServerUrl(environment), }) {
|
|
19
|
+
export async function generateIdToken({ user, client_id, nonce, scopes, jwt_keys, environment, auth_server_url = getAuthServerUrl(environment), auth_server_app_id = getAuthServerAppId(), }) {
|
|
19
20
|
if (typeof user?.uid !== "string" || user.uid.length === 0) {
|
|
20
21
|
throw new TypeError("generateIdToken requires a user with a uid!");
|
|
21
22
|
}
|
|
@@ -42,6 +43,13 @@ export async function generateIdToken({ user, client_id, nonce, scopes, jwt_keys
|
|
|
42
43
|
claims.email = user.email;
|
|
43
44
|
claims.email_verified = user.email_verified ?? false;
|
|
44
45
|
}
|
|
46
|
+
if (scopes.includes("profile")) {
|
|
47
|
+
// OIDC Core §5.1 profile-scoped claims, derived from the user's
|
|
48
|
+
// stored name fields (the `name` claim prefers the public display
|
|
49
|
+
// name). Claims with no stored value are omitted, and /userinfo
|
|
50
|
+
// derives the same claims via the same builder.
|
|
51
|
+
Object.assign(claims, buildOidcProfileClaims(user));
|
|
52
|
+
}
|
|
45
53
|
const id_token = await new SignJWT(claims)
|
|
46
54
|
.setProtectedHeader({
|
|
47
55
|
alg: signAndVerifyAlg,
|
|
@@ -49,7 +57,11 @@ export async function generateIdToken({ user, client_id, nonce, scopes, jwt_keys
|
|
|
49
57
|
kid: `${keyset_id}-verification`,
|
|
50
58
|
})
|
|
51
59
|
.setIssuer(auth_server_url)
|
|
52
|
-
|
|
60
|
+
// The OIDC-facing subject is namespaced by this deployment's app id
|
|
61
|
+
// (`<app_id>|<uid>`); /api/oidc/userinfo and introspection MUST
|
|
62
|
+
// report the same form (OIDC Core §5.3.2 — RP libraries reject a
|
|
63
|
+
// userinfo `sub` that differs from the id_token's).
|
|
64
|
+
.setSubject(formatOidcSubClaim(auth_server_app_id, user.uid))
|
|
53
65
|
.setAudience(client_id)
|
|
54
66
|
// jose defaults to the current unix time in SECONDS; do not pass
|
|
55
67
|
// Date.now() here (milliseconds) like sign.ts does for the internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_id_token.js","sourceRoot":"","sources":["../../src/jwt/generate_id_token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,MAAM,CAAC;AAC/C,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"generate_id_token.js","sourceRoot":"","sources":["../../src/jwt/generate_id_token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,MAAM,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GAEnB,MAAM,2BAA2B,CAAC;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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/jwt",
|
|
3
3
|
"description": "Utility functions for authentication and authorization for use from the auth server or a resource server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"zod": "3.25.8",
|
|
18
18
|
"jose": "6.1.3",
|
|
19
|
-
"@schemavaults/auth-common": "0.
|
|
19
|
+
"@schemavaults/auth-common": "0.25.0",
|
|
20
20
|
"@schemavaults/app-definitions": "0.12.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|