@schemavaults/auth-common 0.26.1 → 0.26.2

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,4 +1,4 @@
1
- export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, } from "./scope";
1
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
2
2
  export type { OidcSupportedScope, OidcScope, ParsedOidcScopes, } from "./scope";
3
3
  export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
4
4
  export type { OidcNonce } from "./nonce";
@@ -1,4 +1,4 @@
1
- export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, } from "./scope";
1
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
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";
@@ -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;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"}
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,EACnB,yBAAyB,GAC1B,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"}
@@ -3,11 +3,20 @@
3
3
  *
4
4
  * The platform's own authorization model is audience-based
5
5
  * (see audience-schema.ts / APP_TO_API_PERMISSIONS); OAuth2 scopes exist
6
- * only on the OIDC surface, where `openid` is mandatory (OIDC Core §3.1.2.1)
7
- * and `email`/`profile` gate which claims the id_token and /userinfo
8
- * response carry. Unknown scopes are silently dropped per RFC 6749 §3.3
9
- * (the granted set is echoed back in the token response, so RPs that
10
- * hardcode e.g. "openid profile email address" still interoperate).
6
+ * only on the OIDC surface, where `openid` turns an authorization
7
+ * request into an OpenID Connect authentication request (OIDC Core
8
+ * §3.1.2.1: an id_token is minted and /userinfo opens up) and
9
+ * `email`/`profile` gate which claims the id_token and /userinfo
10
+ * response carry. A request WITHOUT `openid` including one with no
11
+ * `scope` at all (OPTIONAL per RFC 6749 §3.3) — is a plain OAuth 2.1
12
+ * authorization grant: it yields access + refresh tokens only, no
13
+ * id_token, and no identity claims (OIDC Core §3.1.2.1 leaves such
14
+ * requests to OAuth 2.0 semantics). That is what OAuth-only clients such
15
+ * as MCP clients send; they want a token for a resource server, not an
16
+ * identity. Unknown scopes are silently dropped per RFC 6749 §3.3 (the
17
+ * granted set is echoed back in the token response, so RPs that
18
+ * hardcode e.g. "openid profile email address" still interoperate, and
19
+ * a request naming only unknown scopes degrades to a plain OAuth grant).
11
20
  */
12
21
  import { z } from "zod";
13
22
  export declare const OIDC_OPENID_SCOPE: "openid";
@@ -47,13 +56,19 @@ export interface ParsedOidcScopes {
47
56
  * OIDC_SUPPORTED_SCOPES, deduplicated, in request order.
48
57
  */
49
58
  granted: OidcSupportedScope[];
50
- /** Whether the request included the mandatory `openid` scope. */
59
+ /**
60
+ * Whether the request included the `openid` scope, i.e. whether it is
61
+ * an OpenID Connect authentication request (id_token + userinfo) as
62
+ * opposed to a plain OAuth 2.1 authorization grant.
63
+ */
51
64
  hasOpenid: boolean;
52
65
  }
53
66
  /**
54
67
  * Parses a raw `scope` request parameter (space-delimited per
55
- * RFC 6749 §3.3) into the granted subset. Non-string or empty input
56
- * grants nothing (callers reject missing `openid` via `hasOpenid`).
68
+ * RFC 6749 §3.3) into the granted subset. Non-string, empty, or
69
+ * malformed input grants nothing an empty granted set is a valid
70
+ * outcome (a plain OAuth 2.1 grant); callers that need to distinguish a
71
+ * malformed value from an absent one check `oidcScopeSchema` first.
57
72
  */
58
73
  export declare function parseAndGrantScopes(raw: unknown): ParsedOidcScopes;
59
74
  /**
@@ -61,3 +76,10 @@ export declare function parseAndGrantScopes(raw: unknown): ParsedOidcScopes;
61
76
  * the token response `scope` field and the AUTHORIZATION_CODES row.
62
77
  */
63
78
  export declare function serializeOidcScopes(scopes: readonly string[]): string;
79
+ /**
80
+ * Serializes a granted set to its stored form on the AUTHORIZATION_CODES
81
+ * row / MFA challenge / token claims: `null` when nothing was granted (a
82
+ * plain OAuth 2.1 grant carries no `scope` — the wire format has no
83
+ * representation for an empty list), else the space-delimited list.
84
+ */
85
+ export declare function serializeOidcScopesOrNull(scopes: readonly string[]): string | null;
@@ -3,11 +3,20 @@
3
3
  *
4
4
  * The platform's own authorization model is audience-based
5
5
  * (see audience-schema.ts / APP_TO_API_PERMISSIONS); OAuth2 scopes exist
6
- * only on the OIDC surface, where `openid` is mandatory (OIDC Core §3.1.2.1)
7
- * and `email`/`profile` gate which claims the id_token and /userinfo
8
- * response carry. Unknown scopes are silently dropped per RFC 6749 §3.3
9
- * (the granted set is echoed back in the token response, so RPs that
10
- * hardcode e.g. "openid profile email address" still interoperate).
6
+ * only on the OIDC surface, where `openid` turns an authorization
7
+ * request into an OpenID Connect authentication request (OIDC Core
8
+ * §3.1.2.1: an id_token is minted and /userinfo opens up) and
9
+ * `email`/`profile` gate which claims the id_token and /userinfo
10
+ * response carry. A request WITHOUT `openid` including one with no
11
+ * `scope` at all (OPTIONAL per RFC 6749 §3.3) — is a plain OAuth 2.1
12
+ * authorization grant: it yields access + refresh tokens only, no
13
+ * id_token, and no identity claims (OIDC Core §3.1.2.1 leaves such
14
+ * requests to OAuth 2.0 semantics). That is what OAuth-only clients such
15
+ * as MCP clients send; they want a token for a resource server, not an
16
+ * identity. Unknown scopes are silently dropped per RFC 6749 §3.3 (the
17
+ * granted set is echoed back in the token response, so RPs that
18
+ * hardcode e.g. "openid profile email address" still interoperate, and
19
+ * a request naming only unknown scopes degrades to a plain OAuth grant).
11
20
  */
12
21
  import { z } from "zod";
13
22
  export const OIDC_OPENID_SCOPE = "openid";
@@ -54,8 +63,10 @@ function isSupportedOidcScope(scope) {
54
63
  }
55
64
  /**
56
65
  * Parses a raw `scope` request parameter (space-delimited per
57
- * RFC 6749 §3.3) into the granted subset. Non-string or empty input
58
- * grants nothing (callers reject missing `openid` via `hasOpenid`).
66
+ * RFC 6749 §3.3) into the granted subset. Non-string, empty, or
67
+ * malformed input grants nothing an empty granted set is a valid
68
+ * outcome (a plain OAuth 2.1 grant); callers that need to distinguish a
69
+ * malformed value from an absent one check `oidcScopeSchema` first.
59
70
  */
60
71
  export function parseAndGrantScopes(raw) {
61
72
  if (typeof raw !== "string") {
@@ -81,4 +92,13 @@ export function parseAndGrantScopes(raw) {
81
92
  export function serializeOidcScopes(scopes) {
82
93
  return scopes.join(" ");
83
94
  }
95
+ /**
96
+ * Serializes a granted set to its stored form on the AUTHORIZATION_CODES
97
+ * row / MFA challenge / token claims: `null` when nothing was granted (a
98
+ * plain OAuth 2.1 grant carries no `scope` — the wire format has no
99
+ * representation for an empty list), else the space-delimited list.
100
+ */
101
+ export function serializeOidcScopesOrNull(scopes) {
102
+ return scopes.length === 0 ? null : serializeOidcScopes(scopes);
103
+ }
84
104
  //# sourceMappingURL=scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oidc/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,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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.26.1",
4
+ "version": "0.26.2",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "repository": {