@schemavaults/auth-common 0.25.1 → 0.26.1

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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * OIDC / OAuth2 endpoint paths served by the auth server, relative to
3
+ * its issuer identifier (the auth server URL).
4
+ *
5
+ * Single source of truth shared by:
6
+ * - the auth server's discovery document
7
+ * (`/.well-known/openid-configuration`), which advertises these
8
+ * absolute URLs, and
9
+ * - `@schemavaults/auth-client-sdk`, which builds its `openid-client`
10
+ * Configuration statically from the same paths (skipping a discovery
11
+ * round trip on every client instantiation).
12
+ *
13
+ * The SDK and server must agree byte-for-byte on these, so they are
14
+ * never hardcoded at either end.
15
+ */
16
+ export declare const OIDC_ENDPOINT_PATHS: {
17
+ readonly discovery: "/.well-known/openid-configuration";
18
+ readonly authorization: "/api/oidc/authorize";
19
+ readonly token: "/api/oidc/token";
20
+ readonly userinfo: "/api/oidc/userinfo";
21
+ readonly introspection: "/api/oidc/introspect";
22
+ readonly jwks: "/api/oidc/jwks";
23
+ };
24
+ export type OidcEndpointName = keyof typeof OIDC_ENDPOINT_PATHS;
25
+ /**
26
+ * Resolves an OIDC endpoint to its absolute URL for the given issuer.
27
+ *
28
+ * `issuer` is the auth server URL exactly as it appears in the `iss`
29
+ * claim (never with a trailing slash — see `getAuthServerUrl()`); a
30
+ * trailing slash is tolerated and stripped so the result is stable.
31
+ */
32
+ export declare function getOidcEndpointUrl(issuer: string, endpoint: OidcEndpointName): string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * OIDC / OAuth2 endpoint paths served by the auth server, relative to
3
+ * its issuer identifier (the auth server URL).
4
+ *
5
+ * Single source of truth shared by:
6
+ * - the auth server's discovery document
7
+ * (`/.well-known/openid-configuration`), which advertises these
8
+ * absolute URLs, and
9
+ * - `@schemavaults/auth-client-sdk`, which builds its `openid-client`
10
+ * Configuration statically from the same paths (skipping a discovery
11
+ * round trip on every client instantiation).
12
+ *
13
+ * The SDK and server must agree byte-for-byte on these, so they are
14
+ * never hardcoded at either end.
15
+ */
16
+ export const OIDC_ENDPOINT_PATHS = {
17
+ discovery: "/.well-known/openid-configuration",
18
+ authorization: "/api/oidc/authorize",
19
+ token: "/api/oidc/token",
20
+ userinfo: "/api/oidc/userinfo",
21
+ introspection: "/api/oidc/introspect",
22
+ jwks: "/api/oidc/jwks",
23
+ };
24
+ /**
25
+ * Resolves an OIDC endpoint to its absolute URL for the given issuer.
26
+ *
27
+ * `issuer` is the auth server URL exactly as it appears in the `iss`
28
+ * claim (never with a trailing slash — see `getAuthServerUrl()`); a
29
+ * trailing slash is tolerated and stripped so the result is stable.
30
+ */
31
+ export function getOidcEndpointUrl(issuer, endpoint) {
32
+ if (typeof issuer !== "string" || issuer.length === 0) {
33
+ throw new TypeError("Expected 'issuer' to be a non-empty string!");
34
+ }
35
+ const path = OIDC_ENDPOINT_PATHS[endpoint];
36
+ if (typeof path !== "string") {
37
+ throw new RangeError(`Unknown OIDC endpoint '${String(endpoint)}'`);
38
+ }
39
+ const base = issuer.endsWith("/") ? issuer.slice(0, -1) : issuer;
40
+ return `${base}${path}`;
41
+ }
42
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/oidc/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,mCAAmC;IAC9C,aAAa,EAAE,qBAAqB;IACpC,KAAK,EAAE,iBAAiB;IACxB,QAAQ,EAAE,oBAAoB;IAC9B,aAAa,EAAE,sBAAsB;IACrC,IAAI,EAAE,gBAAgB;CACyB,CAAC;AAIlD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,QAA0B;IAE1B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,IAAI,GAA6B,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACrE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,UAAU,CAAC,0BAA0B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,IAAI,GAAW,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzE,OAAO,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -5,3 +5,9 @@ export type { OidcNonce } from "./nonce";
5
5
  export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
6
6
  export { buildOidcProfileClaims } from "./profile-claims";
7
7
  export type { OidcProfileClaims, OidcProfileClaimsSource, } from "./profile-claims";
8
+ export { OIDC_ENDPOINT_PATHS, getOidcEndpointUrl } from "./endpoints";
9
+ export type { OidcEndpointName } from "./endpoints";
10
+ export { OIDC_TOKEN_RESOURCE_PARAM, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, OIDC_REFRESH_TOKEN_DELIVERY_MODES, oidcRefreshTokenDeliveryModeSchema, DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE, OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD, oidcTokenResponseExtensionsSchema, } from "./token-endpoint-extensions";
11
+ export type { OidcRefreshTokenDeliveryMode, OidcTokenResponseExtensions, } from "./token-endpoint-extensions";
12
+ export { buildOidcProviderMetadata } from "./provider-metadata";
13
+ export type { OidcProviderMetadata } from "./provider-metadata";
@@ -2,4 +2,7 @@ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOP
2
2
  export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
3
3
  export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
4
4
  export { buildOidcProfileClaims } from "./profile-claims";
5
+ export { OIDC_ENDPOINT_PATHS, getOidcEndpointUrl } from "./endpoints";
6
+ export { OIDC_TOKEN_RESOURCE_PARAM, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, OIDC_REFRESH_TOKEN_DELIVERY_MODES, oidcRefreshTokenDeliveryModeSchema, DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE, OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD, oidcTokenResponseExtensionsSchema, } from "./token-endpoint-extensions";
7
+ export { buildOidcProviderMetadata } from "./provider-metadata";
5
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAOjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAOjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtE,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * OpenID Provider Metadata (OIDC Discovery 1.0 §3 / RFC 8414) for the
3
+ * auth server, as a pure function of its issuer identifier.
4
+ *
5
+ * Single source of truth consumed by BOTH ends of the protocol:
6
+ * - the auth server serves it verbatim at
7
+ * /.well-known/openid-configuration, and
8
+ * - `@schemavaults/auth-client-sdk` hands the same object to
9
+ * `openid-client` as its server metadata instead of fetching the
10
+ * document (so the SDK can never drift from what the server
11
+ * advertises — a change here changes both sides together).
12
+ *
13
+ * `issuer` MUST be byte-identical to the `iss` claim in id_tokens and
14
+ * the `iss` authorization-response parameter — both derive from the auth
15
+ * server URL, which never carries a trailing slash.
16
+ */
17
+ /**
18
+ * The advertised metadata. List fields are plain mutable arrays because
19
+ * that is how `openid-client` types its `ServerMetadata`; treat them as
20
+ * read-only in practice (every call builds a fresh document). Declared
21
+ * as a type alias (not an interface) so it carries the implicit index
22
+ * signature `openid-client`'s metadata type requires.
23
+ */
24
+ export type OidcProviderMetadata = {
25
+ issuer: string;
26
+ authorization_endpoint: string;
27
+ token_endpoint: string;
28
+ userinfo_endpoint: string;
29
+ introspection_endpoint: string;
30
+ jwks_uri: string;
31
+ response_types_supported: string[];
32
+ response_modes_supported: string[];
33
+ grant_types_supported: string[];
34
+ subject_types_supported: string[];
35
+ id_token_signing_alg_values_supported: string[];
36
+ scopes_supported: string[];
37
+ token_endpoint_auth_methods_supported: string[];
38
+ introspection_endpoint_auth_methods_supported: string[];
39
+ code_challenge_methods_supported: string[];
40
+ claims_supported: string[];
41
+ authorization_response_iss_parameter_supported: boolean;
42
+ request_parameter_supported: boolean;
43
+ request_uri_parameter_supported: boolean;
44
+ };
45
+ /**
46
+ * Builds the provider metadata for the auth server at `issuer`. A
47
+ * trailing slash on `issuer` is stripped so the endpoints and the
48
+ * `issuer` field stay consistent with the `iss` claim.
49
+ */
50
+ export declare function buildOidcProviderMetadata(issuer: string): OidcProviderMetadata;
51
+ export default buildOidcProviderMetadata;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * OpenID Provider Metadata (OIDC Discovery 1.0 §3 / RFC 8414) for the
3
+ * auth server, as a pure function of its issuer identifier.
4
+ *
5
+ * Single source of truth consumed by BOTH ends of the protocol:
6
+ * - the auth server serves it verbatim at
7
+ * /.well-known/openid-configuration, and
8
+ * - `@schemavaults/auth-client-sdk` hands the same object to
9
+ * `openid-client` as its server metadata instead of fetching the
10
+ * document (so the SDK can never drift from what the server
11
+ * advertises — a change here changes both sides together).
12
+ *
13
+ * `issuer` MUST be byte-identical to the `iss` claim in id_tokens and
14
+ * the `iss` authorization-response parameter — both derive from the auth
15
+ * server URL, which never carries a trailing slash.
16
+ */
17
+ import { getOidcEndpointUrl } from "./endpoints";
18
+ import { OIDC_SUPPORTED_SCOPES } from "./scope";
19
+ /**
20
+ * Builds the provider metadata for the auth server at `issuer`. A
21
+ * trailing slash on `issuer` is stripped so the endpoints and the
22
+ * `issuer` field stay consistent with the `iss` claim.
23
+ */
24
+ export function buildOidcProviderMetadata(issuer) {
25
+ if (typeof issuer !== "string" || issuer.length === 0) {
26
+ throw new TypeError("Expected 'issuer' to be a non-empty string!");
27
+ }
28
+ const normalized_issuer = issuer.endsWith("/")
29
+ ? issuer.slice(0, -1)
30
+ : issuer;
31
+ return {
32
+ issuer: normalized_issuer,
33
+ authorization_endpoint: getOidcEndpointUrl(normalized_issuer, "authorization"),
34
+ token_endpoint: getOidcEndpointUrl(normalized_issuer, "token"),
35
+ userinfo_endpoint: getOidcEndpointUrl(normalized_issuer, "userinfo"),
36
+ introspection_endpoint: getOidcEndpointUrl(normalized_issuer, "introspection"),
37
+ jwks_uri: getOidcEndpointUrl(normalized_issuer, "jwks"),
38
+ response_types_supported: ["code"],
39
+ response_modes_supported: ["query"],
40
+ grant_types_supported: ["authorization_code", "refresh_token"],
41
+ subject_types_supported: ["public"],
42
+ id_token_signing_alg_values_supported: ["RS256"],
43
+ scopes_supported: [...OIDC_SUPPORTED_SCOPES],
44
+ // Apps without a registered client secret are public clients
45
+ // ("none"); apps with one are confidential clients and must
46
+ // authenticate via client_secret_basic or client_secret_post.
47
+ // PKCE S256 is mandatory for every client either way.
48
+ token_endpoint_auth_methods_supported: [
49
+ "none",
50
+ "client_secret_basic",
51
+ "client_secret_post",
52
+ ],
53
+ // RFC 7662 token introspection (advertised per RFC 8414 §2). "none"
54
+ // is deliberately absent: §2.1 requires the endpoint to be
55
+ // authorized, so only confidential clients may introspect.
56
+ introspection_endpoint_auth_methods_supported: [
57
+ "client_secret_basic",
58
+ "client_secret_post",
59
+ ],
60
+ code_challenge_methods_supported: ["S256"],
61
+ claims_supported: [
62
+ "sub",
63
+ "iss",
64
+ "aud",
65
+ "exp",
66
+ "iat",
67
+ "nonce",
68
+ "email",
69
+ "email_verified",
70
+ // Profile-scoped claims (OIDC Core §5.1), derived from the user's
71
+ // stored profile name fields; emitted only when set.
72
+ "name",
73
+ "given_name",
74
+ "middle_name",
75
+ "family_name",
76
+ "preferred_username",
77
+ ],
78
+ // RFC 9207: the auth server puts `iss` on every authorization
79
+ // response. Advertising it makes spec-compliant clients (including
80
+ // the platform SDK via openid-client) require and verify it on
81
+ // redirect callbacks — authorization-server mix-up protection.
82
+ authorization_response_iss_parameter_supported: true,
83
+ // Request Objects (JAR, OIDC Core §6 / RFC 9101) are not implemented;
84
+ // the authorize endpoint rejects `request`/`request_uri` with
85
+ // request_not_supported / request_uri_not_supported. Declared
86
+ // explicitly because OIDC Discovery §3 defaults
87
+ // request_uri_parameter_supported to TRUE when omitted — leaving it
88
+ // out would falsely advertise support.
89
+ request_parameter_supported: false,
90
+ request_uri_parameter_supported: false,
91
+ };
92
+ }
93
+ export default buildOidcProviderMetadata;
94
+ //# sourceMappingURL=provider-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-metadata.js","sourceRoot":"","sources":["../../src/oidc/provider-metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA+BhD;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAc;IAEd,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,iBAAiB,GAAW,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QACpD,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC;IAEX,OAAO;QACL,MAAM,EAAE,iBAAiB;QACzB,sBAAsB,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,eAAe,CAAC;QAC9E,cAAc,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,OAAO,CAAC;QAC9D,iBAAiB,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC;QACpE,sBAAsB,EAAE,kBAAkB,CACxC,iBAAiB,EACjB,eAAe,CAChB;QACD,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,CAAC;QACvD,wBAAwB,EAAE,CAAC,MAAM,CAAC;QAClC,wBAAwB,EAAE,CAAC,OAAO,CAAC;QACnC,qBAAqB,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;QAC9D,uBAAuB,EAAE,CAAC,QAAQ,CAAC;QACnC,qCAAqC,EAAE,CAAC,OAAO,CAAC;QAChD,gBAAgB,EAAE,CAAC,GAAG,qBAAqB,CAAC;QAC5C,6DAA6D;QAC7D,4DAA4D;QAC5D,8DAA8D;QAC9D,sDAAsD;QACtD,qCAAqC,EAAE;YACrC,MAAM;YACN,qBAAqB;YACrB,oBAAoB;SACrB;QACD,oEAAoE;QACpE,2DAA2D;QAC3D,2DAA2D;QAC3D,6CAA6C,EAAE;YAC7C,qBAAqB;YACrB,oBAAoB;SACrB;QACD,gCAAgC,EAAE,CAAC,MAAM,CAAC;QAC1C,gBAAgB,EAAE;YAChB,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,OAAO;YACP,OAAO;YACP,gBAAgB;YAChB,kEAAkE;YAClE,qDAAqD;YACrD,MAAM;YACN,YAAY;YACZ,aAAa;YACb,aAAa;YACb,oBAAoB;SACrB;QACD,8DAA8D;QAC9D,mEAAmE;QACnE,+DAA+D;QAC/D,+DAA+D;QAC/D,8CAA8C,EAAE,IAAI;QACpD,sEAAsE;QACtE,8DAA8D;QAC9D,8DAA8D;QAC9D,gDAAgD;QAChD,oEAAoE;QACpE,uCAAuC;QACvC,2BAA2B,EAAE,KAAK;QAClC,+BAA+B,EAAE,KAAK;KACvC,CAAC;AACJ,CAAC;AAED,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Token-endpoint request/response parameters used by the SchemaVaults
3
+ * SDKs on top of the standard OIDC token endpoint (`/api/oidc/token`).
4
+ *
5
+ * The platform's SDK clients need two things a plain OIDC relying party
6
+ * does not:
7
+ *
8
+ * 1. Access tokens for arbitrary registered API servers (the platform's
9
+ * authorization model is audience-based). This uses the STANDARD
10
+ * RFC 8707 `resource` parameter: the token endpoint mints the
11
+ * response's `access_token` for that audience instead of the
12
+ * reserved `oidc-userinfo` audience. Exactly one `resource` per
13
+ * token request (the platform issues one encrypted access token per
14
+ * audience, so it "only supports issuing an access token with a
15
+ * single audience" in RFC 8707 §2 terms).
16
+ *
17
+ * 2. Refresh tokens kept out of JavaScript for browser clients. This
18
+ * is a platform extension: the `refresh_token_delivery` request
19
+ * parameter asks the endpoint to set the refresh token as an
20
+ * HTTP-only cookie (scoped to the client app, on the auth server's
21
+ * domain) and OMIT `refresh_token` from the JSON body. RFC 6749
22
+ * §5.1 makes `refresh_token` OPTIONAL in the response, so
23
+ * spec-compliant client libraries (e.g. `openid-client`) accept
24
+ * such responses unchanged. The response always carries the
25
+ * extension field `refresh_token_expires_in` (seconds) so the client
26
+ * can track the session lifetime either way.
27
+ *
28
+ * Relying parties that send neither parameter get the plain OIDC
29
+ * behavior (userinfo-audience access token, refresh token inlined).
30
+ */
31
+ import { z } from "zod";
32
+ /** RFC 8707 Resource Indicators request parameter name. */
33
+ export declare const OIDC_TOKEN_RESOURCE_PARAM: "resource";
34
+ /** Platform extension: how the refresh token is delivered to the client. */
35
+ export declare const OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM: "refresh_token_delivery";
36
+ export declare const OIDC_REFRESH_TOKEN_DELIVERY_MODES: readonly ["inline", "http_only_cookie"];
37
+ export declare const oidcRefreshTokenDeliveryModeSchema: z.ZodEnum<{
38
+ inline: "inline";
39
+ http_only_cookie: "http_only_cookie";
40
+ }>;
41
+ export type OidcRefreshTokenDeliveryMode = z.infer<typeof oidcRefreshTokenDeliveryModeSchema>;
42
+ export declare const DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE: "inline";
43
+ /**
44
+ * Platform extension response field: seconds until the (possibly
45
+ * cookie-delivered) refresh token expires. Named after the widely used
46
+ * non-standard field of the same name (GitHub, Keycloak's
47
+ * `refresh_expires_in`, ...).
48
+ */
49
+ export declare const OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD: "refresh_token_expires_in";
50
+ /**
51
+ * Shape of the extension fields the SDK reads off a token response.
52
+ * `refresh_token_expires_in` is emitted by the auth server on every
53
+ * successful response whose grant issued a refresh token.
54
+ */
55
+ export declare const oidcTokenResponseExtensionsSchema: z.ZodObject<{
56
+ refresh_token_expires_in: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$loose>;
58
+ export type OidcTokenResponseExtensions = z.infer<typeof oidcTokenResponseExtensionsSchema>;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Token-endpoint request/response parameters used by the SchemaVaults
3
+ * SDKs on top of the standard OIDC token endpoint (`/api/oidc/token`).
4
+ *
5
+ * The platform's SDK clients need two things a plain OIDC relying party
6
+ * does not:
7
+ *
8
+ * 1. Access tokens for arbitrary registered API servers (the platform's
9
+ * authorization model is audience-based). This uses the STANDARD
10
+ * RFC 8707 `resource` parameter: the token endpoint mints the
11
+ * response's `access_token` for that audience instead of the
12
+ * reserved `oidc-userinfo` audience. Exactly one `resource` per
13
+ * token request (the platform issues one encrypted access token per
14
+ * audience, so it "only supports issuing an access token with a
15
+ * single audience" in RFC 8707 §2 terms).
16
+ *
17
+ * 2. Refresh tokens kept out of JavaScript for browser clients. This
18
+ * is a platform extension: the `refresh_token_delivery` request
19
+ * parameter asks the endpoint to set the refresh token as an
20
+ * HTTP-only cookie (scoped to the client app, on the auth server's
21
+ * domain) and OMIT `refresh_token` from the JSON body. RFC 6749
22
+ * §5.1 makes `refresh_token` OPTIONAL in the response, so
23
+ * spec-compliant client libraries (e.g. `openid-client`) accept
24
+ * such responses unchanged. The response always carries the
25
+ * extension field `refresh_token_expires_in` (seconds) so the client
26
+ * can track the session lifetime either way.
27
+ *
28
+ * Relying parties that send neither parameter get the plain OIDC
29
+ * behavior (userinfo-audience access token, refresh token inlined).
30
+ */
31
+ import { z } from "zod";
32
+ /** RFC 8707 Resource Indicators request parameter name. */
33
+ export const OIDC_TOKEN_RESOURCE_PARAM = "resource";
34
+ /** Platform extension: how the refresh token is delivered to the client. */
35
+ export const OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM = "refresh_token_delivery";
36
+ export const OIDC_REFRESH_TOKEN_DELIVERY_MODES = [
37
+ /** RFC 6749 §5.1 default: `refresh_token` inlined in the JSON body. */
38
+ "inline",
39
+ /**
40
+ * Refresh token set as an HTTP-only cookie (`refresh_token_<client_id>`
41
+ * plus the JS-readable `refresh_token_expiry_<client_id>` marker) and
42
+ * omitted from the JSON body.
43
+ */
44
+ "http_only_cookie",
45
+ ];
46
+ export const oidcRefreshTokenDeliveryModeSchema = z.enum(OIDC_REFRESH_TOKEN_DELIVERY_MODES);
47
+ export const DEFAULT_OIDC_REFRESH_TOKEN_DELIVERY_MODE = "inline";
48
+ /**
49
+ * Platform extension response field: seconds until the (possibly
50
+ * cookie-delivered) refresh token expires. Named after the widely used
51
+ * non-standard field of the same name (GitHub, Keycloak's
52
+ * `refresh_expires_in`, ...).
53
+ */
54
+ export const OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD = "refresh_token_expires_in";
55
+ /**
56
+ * Shape of the extension fields the SDK reads off a token response.
57
+ * `refresh_token_expires_in` is emitted by the auth server on every
58
+ * successful response whose grant issued a refresh token.
59
+ */
60
+ export const oidcTokenResponseExtensionsSchema = z
61
+ .object({
62
+ [OIDC_TOKEN_REFRESH_TOKEN_EXPIRES_IN_FIELD]: z
63
+ .number()
64
+ .int()
65
+ .positive()
66
+ .optional(),
67
+ })
68
+ .loose();
69
+ //# sourceMappingURL=token-endpoint-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-endpoint-extensions.js","sourceRoot":"","sources":["../../src/oidc/token-endpoint-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2DAA2D;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAmB,CAAC;AAE7D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uCAAuC,GAClD,wBAAiC,CAAC;AAEpC,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,uEAAuE;IACvE,QAAQ;IACR;;;;OAIG;IACH,kBAAkB;CACV,CAAC;AAEX,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,CAAC,IAAI,CACtD,iCAAiC,CAClC,CAAC;AAMF,MAAM,CAAC,MAAM,wCAAwC,GACnD,QAAwD,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yCAAyC,GACpD,0BAAmC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC;KAC/C,MAAM,CAAC;IACN,CAAC,yCAAyC,CAAC,EAAE,CAAC;SAC3C,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,EAAE;CACd,CAAC;KACD,KAAK,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schemavaults/auth-common",
3
3
  "description": "Types and utility functions for authentication and authorization",
4
- "version": "0.25.1",
4
+ "version": "0.26.1",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "repository": {