@schemavaults/auth-server-sdk 0.33.6 → 0.35.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.
- package/README.md +91 -3
- package/dist/cli.cjs +2 -2
- package/dist/env/get-schemavaults-resource-url.d.ts +35 -0
- package/dist/env/get-schemavaults-resource-url.js +74 -0
- package/dist/env/get-schemavaults-resource-url.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/isUserInOrganization.d.ts +14 -1
- package/dist/isUserInOrganization.js +12 -6
- package/dist/isUserInOrganization.js.map +1 -1
- package/dist/listUserOrganizations.d.ts +39 -0
- package/dist/listUserOrganizations.js +64 -0
- package/dist/listUserOrganizations.js.map +1 -0
- package/dist/oauth-protected-resource/index.d.ts +3 -0
- package/dist/oauth-protected-resource/index.js +4 -0
- package/dist/oauth-protected-resource/index.js.map +1 -0
- package/dist/oauth-protected-resource/protected-resource-metadata.d.ts +70 -0
- package/dist/oauth-protected-resource/protected-resource-metadata.js +76 -0
- package/dist/oauth-protected-resource/protected-resource-metadata.js.map +1 -0
- package/dist/oauth-protected-resource/route.d.ts +47 -0
- package/dist/oauth-protected-resource/route.js +83 -0
- package/dist/oauth-protected-resource/route.js.map +1 -0
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.d.ts +9 -3
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.js +29 -4
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.js.map +1 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -98,6 +98,63 @@ changes, and only for tokens whose header names one of the listed URLs
|
|
|
98
98
|
(`resolveExpectedTokenAudience()`). Tokens with any other `aud` fail as
|
|
99
99
|
before.
|
|
100
100
|
|
|
101
|
+
`createSchemaVaultsAuthResolvers()` (see below) also accepts the resource URL
|
|
102
|
+
in `SCHEMAVAULTS_RESOURCE_URL` without configuration, with or without a
|
|
103
|
+
trailing slash; elsewhere, list them yourself with `getSchemaVaultsResourceUrl()`
|
|
104
|
+
(null when unset) and `resourceUrlAudiences(url)` from
|
|
105
|
+
`@schemavaults/auth-server-sdk/oauth-protected-resource`.
|
|
106
|
+
|
|
107
|
+
## Protected resource metadata (RFC 9728)
|
|
108
|
+
|
|
109
|
+
OAuth clients that start from nothing but your server's URL (MCP clients do)
|
|
110
|
+
discover which authorization server to use, and which `resource` URL to request
|
|
111
|
+
tokens for, from `/.well-known/oauth-protected-resource`.
|
|
112
|
+
`@schemavaults/auth-server-sdk/oauth-protected-resource` serves that document. In
|
|
113
|
+
Next.js, `app/.well-known/oauth-protected-resource/[[...path]]/route.ts` (the
|
|
114
|
+
optional catch-all also answers the path-suffixed URLs of RFC 9728 §3.1, e.g.
|
|
115
|
+
`/.well-known/oauth-protected-resource/mcp` for `https://api.example.com/mcp`):
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { createOAuthProtectedResourceMetadataRoute } from "@schemavaults/auth-server-sdk/oauth-protected-resource";
|
|
119
|
+
|
|
120
|
+
export const { GET, OPTIONS } = createOAuthProtectedResourceMetadataRoute({
|
|
121
|
+
resource_name: "My API", // optional
|
|
122
|
+
resource_documentation: "/docs", // optional; paths resolve against the resource URL
|
|
123
|
+
scopes_supported: ["mcp:tools"], // optional
|
|
124
|
+
});
|
|
125
|
+
export const dynamic = "force-dynamic";
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"resource": "https://api.example.com/mcp",
|
|
131
|
+
"authorization_servers": ["https://auth.example.com"],
|
|
132
|
+
"bearer_methods_supported": ["header"],
|
|
133
|
+
"resource_name": "My API",
|
|
134
|
+
"resource_documentation": "https://api.example.com/docs"
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- `resource` is `SCHEMAVAULTS_RESOURCE_URL` (or the `resource` option): an
|
|
139
|
+
absolute http(s) URL without query or fragment, `https` in production and
|
|
140
|
+
staging. It is what clients send as RFC 8707 `resource`, so it becomes the
|
|
141
|
+
`aud` of their access tokens; the auth resolvers accept it (above). On the
|
|
142
|
+
auth server the URL must resolve to your API server, or token requests for it
|
|
143
|
+
fail with `invalid_target`: register its origin as one of the API server's
|
|
144
|
+
domains, with `prefix` resource URL matching when the resource URL has a path
|
|
145
|
+
(`exact` suffices when it is the origin itself), and turn on
|
|
146
|
+
`allow_dynamic_clients` for dynamically registered clients.
|
|
147
|
+
- `authorization_servers` is the auth server URL (`SCHEMAVAULTS_AUTH_SERVER_URL`,
|
|
148
|
+
or the environment's default), which is the auth server's issuer.
|
|
149
|
+
- The document is public: `Access-Control-Allow-Origin: *`, cached for an hour,
|
|
150
|
+
and `OPTIONS` answers CORS preflights.
|
|
151
|
+
- Without a resource URL the route answers 404 (no metadata is published); a
|
|
152
|
+
path-suffixed request for a path that is neither the resource's nor below it is
|
|
153
|
+
a 404 too; an invalid resource URL is a 500.
|
|
154
|
+
|
|
155
|
+
`buildOAuthProtectedResourceMetadata()` and `oauthProtectedResourceMetadataUrl()`
|
|
156
|
+
(the RFC 9728 §3.1 metadata URL of a resource URL) are exported for other hosts.
|
|
157
|
+
|
|
101
158
|
## When the JWKS cannot be loaded
|
|
102
159
|
|
|
103
160
|
Route guards verify tokens with the JWKS that `RemoteJwtKeyManager` downloads from the
|
|
@@ -181,7 +238,7 @@ export const api = createOperationsAppFactory<ApiContext, UserData>({
|
|
|
181
238
|
// all optional; environment-derived defaults are read on first request
|
|
182
239
|
apiServerId, // default SCHEMAVAULTS_API_SERVER_ID
|
|
183
240
|
environment, // default getAppEnvironment()
|
|
184
|
-
acceptedAudiences: ["https://mcp.example.com/mcp"], // RFC 8707 resource URLs (see above)
|
|
241
|
+
acceptedAudiences: ["https://mcp.example.com/mcp"], // more RFC 8707 resource URLs; SCHEMAVAULTS_RESOURCE_URL is always accepted (see above)
|
|
185
242
|
isTokenRevoked, // optional revocation hook
|
|
186
243
|
}),
|
|
187
244
|
});
|
|
@@ -201,8 +258,39 @@ Per request:
|
|
|
201
258
|
`auth_not_configured` with a message naming the cause, never a silent pass. With no
|
|
202
259
|
credential at all the operations runtime still answers 401 + `WWW-Authenticate`.
|
|
203
260
|
- The principal is `{ scheme, user, isAdmin: user.admin === true, scope,
|
|
204
|
-
getOrganizationRole }
|
|
205
|
-
(`isUserInOrganization`)
|
|
261
|
+
getOrganizationRole, listOrganizationMemberships }`. `getOrganizationRole` validates the
|
|
262
|
+
id and asks the auth server (`isUserInOrganization`); `listOrganizationMemberships()`
|
|
263
|
+
lists the user's memberships (`listUserOrganizations`, the same
|
|
264
|
+
`OrganizationMembershipRoleDetails` shape as `/api/me/organizations`). Both sign a JWKS
|
|
265
|
+
access assertion with the JWKS access key and forward the token the user presented in
|
|
266
|
+
`X-Subject-Token`.
|
|
267
|
+
|
|
268
|
+
### Organization memberships
|
|
269
|
+
|
|
270
|
+
By default an API server only sees memberships of the organization that owns it:
|
|
271
|
+
`getOrganizationRole` for any other organization fails (the auth server answers 403) and
|
|
272
|
+
`listOrganizationMemberships()` returns at most that one membership. A multi-tenant
|
|
273
|
+
platform service that serves every organization (e.g. a registry) needs a platform
|
|
274
|
+
administrator to set its API server's organization membership visibility to
|
|
275
|
+
`all_organizations` (`PUT /api/apis/{api_server_id}/organization-membership-visibility`
|
|
276
|
+
on the auth server). Lookups outside the owning organization are then answered only
|
|
277
|
+
for a user who presents an active access token for the API server, which the resolvers
|
|
278
|
+
forward automatically; outside operation handlers, pass it yourself:
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
import { isUserInOrganization, listUserOrganizations } from "@schemavaults/auth-server-sdk";
|
|
282
|
+
|
|
283
|
+
const role = await isUserInOrganization(authServerUrl, apiServerId, jwksAccessKey, uid, "acme", {
|
|
284
|
+
subject_token: accessToken, // the user's access token for this API server
|
|
285
|
+
});
|
|
286
|
+
const memberships = await listUserOrganizations({
|
|
287
|
+
auth_server_url: authServerUrl,
|
|
288
|
+
api_server_id: apiServerId,
|
|
289
|
+
jwks_access_private_key: jwksAccessKey,
|
|
290
|
+
uid,
|
|
291
|
+
subject_token: accessToken,
|
|
292
|
+
});
|
|
293
|
+
```
|
|
206
294
|
|
|
207
295
|
`AccessTokenCookieName(apiServerId)` / `AccessTokenExpiryCookieName(apiServerId)` are
|
|
208
296
|
exported from the package index too, so the cookie scheme can be declared without a
|
package/dist/cli.cjs
CHANGED
|
@@ -89,7 +89,7 @@ var init_resolve_codegen_templates_directory = __esm({
|
|
|
89
89
|
|
|
90
90
|
// src/NextjsAppDirectoryPlugin/codegen-marker.ts
|
|
91
91
|
function getCodegenMarkerComment() {
|
|
92
|
-
const version = true ? "0.
|
|
92
|
+
const version = true ? "0.35.0" : "unknown";
|
|
93
93
|
return `${CODEGEN_MARKER_PREFIX}${version}`;
|
|
94
94
|
}
|
|
95
95
|
function hasCodegenMarker(firstLine) {
|
|
@@ -345,7 +345,7 @@ async function main() {
|
|
|
345
345
|
return;
|
|
346
346
|
}
|
|
347
347
|
if (args.includes("--version") || args.includes("-v")) {
|
|
348
|
-
console.log(`${PACKAGE_NAME}@${"0.
|
|
348
|
+
console.log(`${PACKAGE_NAME}@${"0.35.0"}`);
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
351
|
const command = args.find((arg) => !arg.startsWith("-")) ?? "codegen";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
+
/**
|
|
3
|
+
* The environment variable holding this resource server's resource
|
|
4
|
+
* identifier: the URL clients name it by (an RFC 8707 `resource`), the
|
|
5
|
+
* `resource` of its RFC 9728 protected resource metadata, and therefore
|
|
6
|
+
* the `aud` of the access tokens such clients obtain for it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RESOURCE_URL_ENV_VAR_NAME: "SCHEMAVAULTS_RESOURCE_URL";
|
|
9
|
+
/**
|
|
10
|
+
* @description Validates a resource identifier (RFC 9728 §1.2 / RFC 8707
|
|
11
|
+
* §2): an absolute http(s) URL without query or fragment. `https` is
|
|
12
|
+
* required in production and staging. The value is returned verbatim
|
|
13
|
+
* (only surrounding whitespace is trimmed), since it becomes a token
|
|
14
|
+
* audience that is compared byte for byte.
|
|
15
|
+
*
|
|
16
|
+
* @throws TypeError when the value is not a usable resource identifier.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseResourceUrl(value: string, environment?: SchemaVaultsAppEnvironment): string;
|
|
19
|
+
/**
|
|
20
|
+
* @returns The resource URL configured in `SCHEMAVAULTS_RESOURCE_URL`, or
|
|
21
|
+
* null when it is unset or empty.
|
|
22
|
+
* @throws TypeError when it is set to something that is not a usable
|
|
23
|
+
* resource identifier (see {@link parseResourceUrl}).
|
|
24
|
+
*/
|
|
25
|
+
export declare function getSchemaVaultsResourceUrl(environment?: SchemaVaultsAppEnvironment): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* @description The token audiences a resource URL stands for: the URL
|
|
28
|
+
* itself and its twin with (or without) one trailing slash. Clients that
|
|
29
|
+
* normalize the URL they read from the protected resource metadata
|
|
30
|
+
* (`new URL("https://api.example.com").href` is `https://api.example.com/`)
|
|
31
|
+
* request their tokens with the other spelling; the auth server resolves
|
|
32
|
+
* both to the same API server, and both are this server's own audience.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resourceUrlAudiences(resource_url: string): readonly string[];
|
|
35
|
+
export default getSchemaVaultsResourceUrl;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getAppEnvironment, } from "@schemavaults/app-definitions";
|
|
2
|
+
/**
|
|
3
|
+
* The environment variable holding this resource server's resource
|
|
4
|
+
* identifier: the URL clients name it by (an RFC 8707 `resource`), the
|
|
5
|
+
* `resource` of its RFC 9728 protected resource metadata, and therefore
|
|
6
|
+
* the `aud` of the access tokens such clients obtain for it.
|
|
7
|
+
*/
|
|
8
|
+
export const RESOURCE_URL_ENV_VAR_NAME = "SCHEMAVAULTS_RESOURCE_URL";
|
|
9
|
+
/**
|
|
10
|
+
* @description Validates a resource identifier (RFC 9728 §1.2 / RFC 8707
|
|
11
|
+
* §2): an absolute http(s) URL without query or fragment. `https` is
|
|
12
|
+
* required in production and staging. The value is returned verbatim
|
|
13
|
+
* (only surrounding whitespace is trimmed), since it becomes a token
|
|
14
|
+
* audience that is compared byte for byte.
|
|
15
|
+
*
|
|
16
|
+
* @throws TypeError when the value is not a usable resource identifier.
|
|
17
|
+
*/
|
|
18
|
+
export function parseResourceUrl(value, environment = getAppEnvironment()) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(trimmed);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new TypeError(`Resource URL is not an absolute URL: '${value}'`);
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
28
|
+
throw new TypeError(`Resource URL must be an http(s) URL: '${value}'`);
|
|
29
|
+
}
|
|
30
|
+
if (url.protocol !== "https:" && (environment === "production" || environment === "staging")) {
|
|
31
|
+
throw new TypeError(`Resource URL must use https in ${environment}: '${value}'`);
|
|
32
|
+
}
|
|
33
|
+
if (trimmed.includes("?") || trimmed.includes("#")) {
|
|
34
|
+
throw new TypeError(`Resource URL must not include a query or fragment: '${value}'`);
|
|
35
|
+
}
|
|
36
|
+
if (url.username || url.password) {
|
|
37
|
+
throw new TypeError(`Resource URL must not include credentials: '${value}'`);
|
|
38
|
+
}
|
|
39
|
+
return trimmed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @returns The resource URL configured in `SCHEMAVAULTS_RESOURCE_URL`, or
|
|
43
|
+
* null when it is unset or empty.
|
|
44
|
+
* @throws TypeError when it is set to something that is not a usable
|
|
45
|
+
* resource identifier (see {@link parseResourceUrl}).
|
|
46
|
+
*/
|
|
47
|
+
export function getSchemaVaultsResourceUrl(environment) {
|
|
48
|
+
const raw = process.env[RESOURCE_URL_ENV_VAR_NAME];
|
|
49
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return parseResourceUrl(raw, environment);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new TypeError(`Invalid '${RESOURCE_URL_ENV_VAR_NAME}' environment variable: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @description The token audiences a resource URL stands for: the URL
|
|
61
|
+
* itself and its twin with (or without) one trailing slash. Clients that
|
|
62
|
+
* normalize the URL they read from the protected resource metadata
|
|
63
|
+
* (`new URL("https://api.example.com").href` is `https://api.example.com/`)
|
|
64
|
+
* request their tokens with the other spelling; the auth server resolves
|
|
65
|
+
* both to the same API server, and both are this server's own audience.
|
|
66
|
+
*/
|
|
67
|
+
export function resourceUrlAudiences(resource_url) {
|
|
68
|
+
const without = resource_url.endsWith("/")
|
|
69
|
+
? resource_url.slice(0, -1)
|
|
70
|
+
: resource_url;
|
|
71
|
+
return [resource_url, resource_url === without ? `${without}/` : without];
|
|
72
|
+
}
|
|
73
|
+
export default getSchemaVaultsResourceUrl;
|
|
74
|
+
//# sourceMappingURL=get-schemavaults-resource-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-schemavaults-resource-url.js","sourceRoot":"","sources":["../../src/env/get-schemavaults-resource-url.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAAoC,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,cAA0C,iBAAiB,EAAE;IAE7D,MAAM,OAAO,GAAW,KAAK,CAAC,IAAI,EAAE,CAAC;IACrC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,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,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CACjB,YAAY,yBAAyB,2BAA2B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAC5G,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAoB;IACvD,MAAM,OAAO,GAAW,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QAChD,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC,CAAC,YAAY,CAAC;IACjB,OAAO,CAAC,YAAY,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED,eAAe,0BAA0B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ export { decodeJWTsWithKeyManager } from "./decode-jwts-with-key-manager";
|
|
|
30
30
|
export type { IDecodeJWTsWithKeyManagerOutput, DecodeJWTsWithKeyManagerOptions, } from "./decode-jwts-with-key-manager";
|
|
31
31
|
export { resolveExpectedTokenAudience, normalizeAcceptedAudiences, } from "./resolve-expected-token-audience";
|
|
32
32
|
export { isUserInOrganization } from "./isUserInOrganization";
|
|
33
|
+
export type { IIsUserInOrganizationOptions } from "./isUserInOrganization";
|
|
34
|
+
export { listUserOrganizations, SUBJECT_TOKEN_HEADER_NAME, } from "./listUserOrganizations";
|
|
35
|
+
export type { IListUserOrganizationsOptions } from "./listUserOrganizations";
|
|
33
36
|
export { introspectToken, tokenIntrospectionResultSchema, } from "./introspectToken";
|
|
34
37
|
export type { IIntrospectTokenOptions, TokenIntrospectionResult, } from "./introspectToken";
|
|
35
38
|
export { userDataSchema } from "@schemavaults/auth-common";
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export { decodeJWTsWithKeyManager } from "./decode-jwts-with-key-manager";
|
|
|
25
25
|
export { resolveExpectedTokenAudience, normalizeAcceptedAudiences, } from "./resolve-expected-token-audience";
|
|
26
26
|
// Check user organization membership from auth server (for resource servers)
|
|
27
27
|
export { isUserInOrganization } from "./isUserInOrganization";
|
|
28
|
+
export { listUserOrganizations, SUBJECT_TOKEN_HEADER_NAME, } from "./listUserOrganizations";
|
|
28
29
|
// RFC 7662 token introspection of this API server's access tokens
|
|
29
30
|
export { introspectToken, tokenIntrospectionResultSchema, } from "./introspectToken";
|
|
30
31
|
// Re-export user data types
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAG7B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAG7C,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAEpC,iBAAiB;AACjB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,IAAI,0BAA0B,EACzD,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,yBAAyB;AACzB,OAAO,EACL,kCAAkC,EAClC,kCAAkC,IAAI,kCAAkC,EACzE,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,eAAe;AACf,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,qBAAqB,E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,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,+BAA+B;AAC/B,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,gCAAgC,EAChC,yCAAyC,EACzC,qCAAqC,EACrC,+BAA+B,EAC/B,oCAAoC,GACrC,MAAM,yCAAyC,CAAC;AAmBjD,8BAA8B;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,kDAAkD;AAClD,OAAO,EAAE,OAAO,IAAI,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
2
|
import { type OrganizationID, type OrganizationMembershipRoleType } from "@schemavaults/auth-common/organizations";
|
|
3
|
+
export interface IIsUserInOrganizationOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The user's access token for this API server, as presented to the
|
|
6
|
+
* resource server. Required by the auth server when `organization_id` is
|
|
7
|
+
* not the API server's own organization (only API servers granted the
|
|
8
|
+
* `all_organizations` membership visibility may ask about those);
|
|
9
|
+
* ignored for the API server's own organization.
|
|
10
|
+
*/
|
|
11
|
+
subject_token?: string;
|
|
12
|
+
/** Override for tests. */
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Check if a user is a member of an organization by querying the auth server.
|
|
5
17
|
*
|
|
@@ -12,7 +24,8 @@ import { type OrganizationID, type OrganizationMembershipRoleType } from "@schem
|
|
|
12
24
|
* @param jwks_access_private_key - The JWKS access private key for signing assertions
|
|
13
25
|
* @param uid - The user ID to check membership for
|
|
14
26
|
* @param organization_id - The organization to check membership in
|
|
27
|
+
* @param options - See {@link IIsUserInOrganizationOptions}
|
|
15
28
|
* @returns false if not a member, or the role name string (e.g. "owner", "member") if they are
|
|
16
29
|
*/
|
|
17
|
-
export declare function isUserInOrganization(auth_server_url: string, api_server_id: ApiServerId, jwks_access_private_key: CryptoKey, uid: string, organization_id: OrganizationID): Promise<OrganizationMembershipRoleType | false>;
|
|
30
|
+
export declare function isUserInOrganization(auth_server_url: string, api_server_id: ApiServerId, jwks_access_private_key: CryptoKey, uid: string, organization_id: OrganizationID, options?: IIsUserInOrganizationOptions): Promise<OrganizationMembershipRoleType | false>;
|
|
18
31
|
export default isUserInOrganization;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createJwksAccessProofToken } from "@schemavaults/jwt";
|
|
2
2
|
import { apiServerIdSchema, } from "@schemavaults/app-definitions";
|
|
3
3
|
import { isValidOrganizationMembershipRoleType, organizationIdSchema, } from "@schemavaults/auth-common/organizations";
|
|
4
|
+
import { SUBJECT_TOKEN_HEADER_NAME } from "./listUserOrganizations";
|
|
4
5
|
/**
|
|
5
6
|
* Check if a user is a member of an organization by querying the auth server.
|
|
6
7
|
*
|
|
@@ -13,9 +14,10 @@ import { isValidOrganizationMembershipRoleType, organizationIdSchema, } from "@s
|
|
|
13
14
|
* @param jwks_access_private_key - The JWKS access private key for signing assertions
|
|
14
15
|
* @param uid - The user ID to check membership for
|
|
15
16
|
* @param organization_id - The organization to check membership in
|
|
17
|
+
* @param options - See {@link IIsUserInOrganizationOptions}
|
|
16
18
|
* @returns false if not a member, or the role name string (e.g. "owner", "member") if they are
|
|
17
19
|
*/
|
|
18
|
-
export async function isUserInOrganization(auth_server_url, api_server_id, jwks_access_private_key, uid, organization_id) {
|
|
20
|
+
export async function isUserInOrganization(auth_server_url, api_server_id, jwks_access_private_key, uid, organization_id, options = {}) {
|
|
19
21
|
if (!apiServerIdSchema.safeParse(api_server_id).success) {
|
|
20
22
|
throw new TypeError("Invalid API server ID!");
|
|
21
23
|
}
|
|
@@ -31,12 +33,16 @@ export async function isUserInOrganization(auth_server_url, api_server_id, jwks_
|
|
|
31
33
|
private_key: jwks_access_private_key,
|
|
32
34
|
});
|
|
33
35
|
const url = new URL(`/api/resource-server/organizations/${encodeURIComponent(organization_id)}/members/${encodeURIComponent(uid)}/role`, auth_server_url);
|
|
34
|
-
const
|
|
36
|
+
const headers = new Headers({
|
|
37
|
+
Authorization: `Bearer ${assertion}`,
|
|
38
|
+
"X-Api-Server-Id": api_server_id,
|
|
39
|
+
});
|
|
40
|
+
if (typeof options.subject_token === "string" && options.subject_token.length > 0) {
|
|
41
|
+
headers.set(SUBJECT_TOKEN_HEADER_NAME, options.subject_token);
|
|
42
|
+
}
|
|
43
|
+
const response = await (options.fetch ?? fetch)(url.toString(), {
|
|
35
44
|
method: "GET",
|
|
36
|
-
headers
|
|
37
|
-
Authorization: `Bearer ${assertion}`,
|
|
38
|
-
"X-Api-Server-Id": api_server_id,
|
|
39
|
-
}),
|
|
45
|
+
headers,
|
|
40
46
|
});
|
|
41
47
|
if (!response.ok) {
|
|
42
48
|
throw new Error(`Failed to check organization membership from auth server (status: ${response.status})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUserInOrganization.js","sourceRoot":"","sources":["../src/isUserInOrganization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qCAAqC,EACrC,oBAAoB,GAGrB,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"isUserInOrganization.js","sourceRoot":"","sources":["../src/isUserInOrganization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,qCAAqC,EACrC,oBAAoB,GAGrB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAepE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK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;KACR,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,qEAAqE,QAAQ,CAAC,MAAM,GAAG,CACxF,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC5C,IACE,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,IAAI;QACL,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC;QACpB,CAAC,IAAI,CAAC,OAAO;QACb,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAC7B,CAAC,IAAI,CAAC,IAAI,EACV,CAAC;QACD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAA+B,CAAC;IAClD,IACE,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAC7B,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,EAChD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type OrganizationMembershipRoleDetails } from "@schemavaults/auth-common/organizations";
|
|
3
|
+
/** Header the user's access token is forwarded in (the RFC 8693 "subject token"). */
|
|
4
|
+
export declare const SUBJECT_TOKEN_HEADER_NAME: "X-Subject-Token";
|
|
5
|
+
export interface IListUserOrganizationsOptions {
|
|
6
|
+
/** Base URL of the auth server. */
|
|
7
|
+
auth_server_url: string;
|
|
8
|
+
/** The calling resource server's API server id. */
|
|
9
|
+
api_server_id: ApiServerId;
|
|
10
|
+
/** The API server's JWKS access private key (signs the single-use assertion). */
|
|
11
|
+
jwks_access_private_key: CryptoKey;
|
|
12
|
+
/** The user to list the memberships of. */
|
|
13
|
+
uid: string;
|
|
14
|
+
/**
|
|
15
|
+
* The user's access token for this API server, exactly as it was
|
|
16
|
+
* presented to the resource server. The auth server only answers for a
|
|
17
|
+
* user who holds an active token for the calling API server.
|
|
18
|
+
*/
|
|
19
|
+
subject_token: string;
|
|
20
|
+
/** Override for tests. */
|
|
21
|
+
fetch?: typeof fetch;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Lists a user's organization memberships by asking the auth server
|
|
25
|
+
* (`GET /api/resource-server/users/{uid}/organizations`), for resource
|
|
26
|
+
* servers that show or filter by "my organizations".
|
|
27
|
+
*
|
|
28
|
+
* Authenticates as the API server with a JWKS access assertion and
|
|
29
|
+
* forwards the user's access token in `X-Subject-Token`. The auth server
|
|
30
|
+
* returns only the memberships the API server may see: its owning
|
|
31
|
+
* organization's, or every organization's when a platform administrator
|
|
32
|
+
* granted it the `all_organizations` membership visibility.
|
|
33
|
+
*
|
|
34
|
+
* @throws when the auth server refuses the request (e.g. 403 for a
|
|
35
|
+
* subject token that is not an active token of `uid` for this API server)
|
|
36
|
+
* or answers with an unexpected body.
|
|
37
|
+
*/
|
|
38
|
+
export declare function listUserOrganizations({ auth_server_url, api_server_id, jwks_access_private_key, uid, subject_token, fetch: fetchImpl, }: IListUserOrganizationsOptions): Promise<readonly OrganizationMembershipRoleDetails[]>;
|
|
39
|
+
export default listUserOrganizations;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createJwksAccessProofToken } from "@schemavaults/jwt";
|
|
2
|
+
import { apiServerIdSchema, } from "@schemavaults/app-definitions";
|
|
3
|
+
import { organizationMembershipRoleDetailsSchema, } from "@schemavaults/auth-common/organizations";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import isValidUuid from "./is-valid-uuid";
|
|
6
|
+
/** Header the user's access token is forwarded in (the RFC 8693 "subject token"). */
|
|
7
|
+
export const SUBJECT_TOKEN_HEADER_NAME = "X-Subject-Token";
|
|
8
|
+
const listUserOrganizationsResponseSchema = z.object({
|
|
9
|
+
success: z.literal(true),
|
|
10
|
+
data: z.object({
|
|
11
|
+
uid: z.string(),
|
|
12
|
+
memberships: z.array(organizationMembershipRoleDetailsSchema),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Lists a user's organization memberships by asking the auth server
|
|
17
|
+
* (`GET /api/resource-server/users/{uid}/organizations`), for resource
|
|
18
|
+
* servers that show or filter by "my organizations".
|
|
19
|
+
*
|
|
20
|
+
* Authenticates as the API server with a JWKS access assertion and
|
|
21
|
+
* forwards the user's access token in `X-Subject-Token`. The auth server
|
|
22
|
+
* returns only the memberships the API server may see: its owning
|
|
23
|
+
* organization's, or every organization's when a platform administrator
|
|
24
|
+
* granted it the `all_organizations` membership visibility.
|
|
25
|
+
*
|
|
26
|
+
* @throws when the auth server refuses the request (e.g. 403 for a
|
|
27
|
+
* subject token that is not an active token of `uid` for this API server)
|
|
28
|
+
* or answers with an unexpected body.
|
|
29
|
+
*/
|
|
30
|
+
export async function listUserOrganizations({ auth_server_url, api_server_id, jwks_access_private_key, uid, subject_token, fetch: fetchImpl = fetch, }) {
|
|
31
|
+
if (!apiServerIdSchema.safeParse(api_server_id).success) {
|
|
32
|
+
throw new TypeError("Invalid API server ID!");
|
|
33
|
+
}
|
|
34
|
+
if (!isValidUuid(uid)) {
|
|
35
|
+
throw new TypeError("Invalid user ID!");
|
|
36
|
+
}
|
|
37
|
+
if (typeof subject_token !== "string" || subject_token.length === 0) {
|
|
38
|
+
throw new TypeError("A subject token (the user's access token) is required!");
|
|
39
|
+
}
|
|
40
|
+
const assertion = await createJwksAccessProofToken({
|
|
41
|
+
api_server_id,
|
|
42
|
+
auth_server_url,
|
|
43
|
+
private_key: jwks_access_private_key,
|
|
44
|
+
});
|
|
45
|
+
const url = new URL(`/api/resource-server/users/${encodeURIComponent(uid)}/organizations`, auth_server_url);
|
|
46
|
+
const response = await fetchImpl(url.toString(), {
|
|
47
|
+
method: "GET",
|
|
48
|
+
headers: new Headers({
|
|
49
|
+
Authorization: `Bearer ${assertion}`,
|
|
50
|
+
"X-Api-Server-Id": api_server_id,
|
|
51
|
+
[SUBJECT_TOKEN_HEADER_NAME]: subject_token,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`Failed to list organization memberships from auth server (status: ${response.status})`);
|
|
56
|
+
}
|
|
57
|
+
const parsed = listUserOrganizationsResponseSchema.safeParse(await response.json());
|
|
58
|
+
if (!parsed.success || parsed.data.data.uid !== uid) {
|
|
59
|
+
throw new Error("Received unexpected response when listing organization memberships");
|
|
60
|
+
}
|
|
61
|
+
return parsed.data.data.memberships;
|
|
62
|
+
}
|
|
63
|
+
export default listUserOrganizations;
|
|
64
|
+
//# sourceMappingURL=listUserOrganizations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listUserOrganizations.js","sourceRoot":"","sources":["../src/listUserOrganizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,uCAAuC,GAExC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAE1C,qFAAqF;AACrF,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAA0B,CAAC;AAqBpE,MAAM,mCAAmC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACb,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,uCAAuC,CAAC;KAC9D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M,MAAM,GAAG,mCAAmC,CAAC,SAAS,CAC1D,MAAM,QAAQ,CAAC,IAAI,EAAE,CACtB,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;AACtC,CAAC;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createOAuthProtectedResourceMetadataRoute, type OAuthProtectedResourceMetadataRouteHandler, type OAuthProtectedResourceMetadataRouteOptions, } from "./route";
|
|
2
|
+
export { OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH, buildOAuthProtectedResourceMetadata, isMetadataRequestForResource, oauthProtectedResourceMetadataUrl, type BuildOAuthProtectedResourceMetadataOptions, type OAuthProtectedResourceMetadata, type OAuthProtectedResourceMetadataDetails, } from "./protected-resource-metadata";
|
|
3
|
+
export { RESOURCE_URL_ENV_VAR_NAME, getSchemaVaultsResourceUrl, parseResourceUrl, resourceUrlAudiences, } from "../env/get-schemavaults-resource-url";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createOAuthProtectedResourceMetadataRoute, } from "./route";
|
|
2
|
+
export { OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH, buildOAuthProtectedResourceMetadata, isMetadataRequestForResource, oauthProtectedResourceMetadataUrl, } from "./protected-resource-metadata";
|
|
3
|
+
export { RESOURCE_URL_ENV_VAR_NAME, getSchemaVaultsResourceUrl, parseResourceUrl, resourceUrlAudiences, } from "../env/get-schemavaults-resource-url";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oauth-protected-resource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,GAG1C,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,wCAAwC,EACxC,mCAAmC,EACnC,4BAA4B,EAC5B,iCAAiC,GAIlC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The well-known path suffix of OAuth 2.0 Protected Resource Metadata
|
|
3
|
+
* (RFC 9728 §3).
|
|
4
|
+
*/
|
|
5
|
+
export declare const OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH: "/.well-known/oauth-protected-resource";
|
|
6
|
+
/**
|
|
7
|
+
* OAuth 2.0 Protected Resource Metadata (RFC 9728 §2), as served by
|
|
8
|
+
* resource servers built on this SDK. Tokens for them are presented as
|
|
9
|
+
* `Authorization: Bearer` headers (the first-party access-token cookie is
|
|
10
|
+
* not an RFC 6750 method, so it is not advertised).
|
|
11
|
+
*/
|
|
12
|
+
export interface OAuthProtectedResourceMetadata {
|
|
13
|
+
/** The resource identifier: the URL clients request tokens for (RFC 8707 `resource`). */
|
|
14
|
+
readonly resource: string;
|
|
15
|
+
/** Issuer identifiers of the authorization servers that issue tokens for this resource. */
|
|
16
|
+
readonly authorization_servers: readonly string[];
|
|
17
|
+
readonly bearer_methods_supported: readonly ["header"];
|
|
18
|
+
readonly scopes_supported?: readonly string[];
|
|
19
|
+
readonly resource_name?: string;
|
|
20
|
+
readonly resource_documentation?: string;
|
|
21
|
+
readonly resource_policy_uri?: string;
|
|
22
|
+
readonly resource_tos_uri?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Human-readable / optional members of the metadata a resource server may set. */
|
|
25
|
+
export interface OAuthProtectedResourceMetadataDetails {
|
|
26
|
+
/** Scope values clients may request for this resource (`scopes_supported`). */
|
|
27
|
+
readonly scopes_supported?: readonly string[];
|
|
28
|
+
/** Name of the resource intended for display to end users (`resource_name`). */
|
|
29
|
+
readonly resource_name?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Developer documentation of the resource (`resource_documentation`). A
|
|
32
|
+
* path (`/docs`) is resolved against the resource URL's origin.
|
|
33
|
+
*/
|
|
34
|
+
readonly resource_documentation?: string;
|
|
35
|
+
/** Policy on how clients may use the resource's data. Paths resolve like `resource_documentation`. */
|
|
36
|
+
readonly resource_policy_uri?: string;
|
|
37
|
+
/** Terms of service of the resource. Paths resolve like `resource_documentation`. */
|
|
38
|
+
readonly resource_tos_uri?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface BuildOAuthProtectedResourceMetadataOptions extends OAuthProtectedResourceMetadataDetails {
|
|
41
|
+
/** The resource identifier, verbatim. */
|
|
42
|
+
readonly resource: string;
|
|
43
|
+
/** Issuer identifiers; one trailing slash is removed from each (issuers never carry one). */
|
|
44
|
+
readonly authorization_servers: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @description Builds the protected resource metadata document. Optional
|
|
48
|
+
* members are omitted when not set; `scopes_supported` is omitted when
|
|
49
|
+
* empty.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildOAuthProtectedResourceMetadata(options: BuildOAuthProtectedResourceMetadataOptions): OAuthProtectedResourceMetadata;
|
|
52
|
+
/**
|
|
53
|
+
* @description The URL a client fetches a resource's metadata from (RFC
|
|
54
|
+
* 9728 §3.1): the well-known path inserted between the host and the
|
|
55
|
+
* resource's path, without the path's terminating slash.
|
|
56
|
+
*
|
|
57
|
+
* `https://api.example.com` → `https://api.example.com/.well-known/oauth-protected-resource`;
|
|
58
|
+
* `https://api.example.com/mcp` → `https://api.example.com/.well-known/oauth-protected-resource/mcp`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function oauthProtectedResourceMetadataUrl(resource_url: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* @description Whether a metadata request for `request_pathname` is about
|
|
63
|
+
* `resource_url`. The bare well-known path (and a request that reached
|
|
64
|
+
* the handler under any other path, e.g. through a rewrite) is answered
|
|
65
|
+
* for every resource; a path-suffixed request (RFC 9728 §3.1) only when
|
|
66
|
+
* the suffix is the resource's path or a `/`-delimited path below it, as
|
|
67
|
+
* MCP clients ask about their server URL (`/mcp/v1`) before falling back
|
|
68
|
+
* to the bare path.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isMetadataRequestForResource(request_pathname: string, resource_url: string): boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The well-known path suffix of OAuth 2.0 Protected Resource Metadata
|
|
3
|
+
* (RFC 9728 §3).
|
|
4
|
+
*/
|
|
5
|
+
export const OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH = "/.well-known/oauth-protected-resource";
|
|
6
|
+
function stripTrailingSlash(value) {
|
|
7
|
+
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
8
|
+
}
|
|
9
|
+
function resolveAgainstResource(value, resource) {
|
|
10
|
+
return value.startsWith("/") ? new URL(value, new URL(resource).origin).href : value;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @description Builds the protected resource metadata document. Optional
|
|
14
|
+
* members are omitted when not set; `scopes_supported` is omitted when
|
|
15
|
+
* empty.
|
|
16
|
+
*/
|
|
17
|
+
export function buildOAuthProtectedResourceMetadata(options) {
|
|
18
|
+
const { resource } = options;
|
|
19
|
+
const uri = (value) => typeof value === "string" && value.length > 0
|
|
20
|
+
? resolveAgainstResource(value, resource)
|
|
21
|
+
: undefined;
|
|
22
|
+
const resource_documentation = uri(options.resource_documentation);
|
|
23
|
+
const resource_policy_uri = uri(options.resource_policy_uri);
|
|
24
|
+
const resource_tos_uri = uri(options.resource_tos_uri);
|
|
25
|
+
return {
|
|
26
|
+
resource,
|
|
27
|
+
authorization_servers: options.authorization_servers.map(stripTrailingSlash),
|
|
28
|
+
bearer_methods_supported: ["header"],
|
|
29
|
+
...(options.scopes_supported && options.scopes_supported.length > 0
|
|
30
|
+
? { scopes_supported: [...options.scopes_supported] }
|
|
31
|
+
: {}),
|
|
32
|
+
...(options.resource_name ? { resource_name: options.resource_name } : {}),
|
|
33
|
+
...(resource_documentation ? { resource_documentation } : {}),
|
|
34
|
+
...(resource_policy_uri ? { resource_policy_uri } : {}),
|
|
35
|
+
...(resource_tos_uri ? { resource_tos_uri } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description The URL a client fetches a resource's metadata from (RFC
|
|
40
|
+
* 9728 §3.1): the well-known path inserted between the host and the
|
|
41
|
+
* resource's path, without the path's terminating slash.
|
|
42
|
+
*
|
|
43
|
+
* `https://api.example.com` → `https://api.example.com/.well-known/oauth-protected-resource`;
|
|
44
|
+
* `https://api.example.com/mcp` → `https://api.example.com/.well-known/oauth-protected-resource/mcp`.
|
|
45
|
+
*/
|
|
46
|
+
export function oauthProtectedResourceMetadataUrl(resource_url) {
|
|
47
|
+
const url = new URL(resource_url);
|
|
48
|
+
const path = url.pathname === "/" ? "" : stripTrailingSlash(url.pathname);
|
|
49
|
+
return `${url.origin}${OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH}${path}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @description Whether a metadata request for `request_pathname` is about
|
|
53
|
+
* `resource_url`. The bare well-known path (and a request that reached
|
|
54
|
+
* the handler under any other path, e.g. through a rewrite) is answered
|
|
55
|
+
* for every resource; a path-suffixed request (RFC 9728 §3.1) only when
|
|
56
|
+
* the suffix is the resource's path or a `/`-delimited path below it, as
|
|
57
|
+
* MCP clients ask about their server URL (`/mcp/v1`) before falling back
|
|
58
|
+
* to the bare path.
|
|
59
|
+
*/
|
|
60
|
+
export function isMetadataRequestForResource(request_pathname, resource_url) {
|
|
61
|
+
if (!request_pathname.startsWith(OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const suffix = stripTrailingSlash(request_pathname.slice(OAUTH_PROTECTED_RESOURCE_WELL_KNOWN_PATH.length));
|
|
65
|
+
if (suffix.length === 0) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (!suffix.startsWith("/")) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const resource_path = stripTrailingSlash(new URL(resource_url).pathname);
|
|
72
|
+
return (resource_path.length === 0 ||
|
|
73
|
+
suffix === resource_path ||
|
|
74
|
+
suffix.startsWith(`${resource_path}/`));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=protected-resource-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-resource-metadata.js","sourceRoot":"","sources":["../../src/oauth-protected-resource/protected-resource-metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,wCAAwC,GACnD,uCAAgD,CAAC;AA8CnD,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1D,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa,EAAE,QAAgB;IAC7D,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CACjD,OAAmD;IAEnD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,GAAG,GAAG,CAAC,KAAyB,EAAsB,EAAE,CAC5D,OAAO,KAAK,KAAK,QAAQ,IAAI,K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AAM,IAAI,GAAW,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClF,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,wCAAwC,GAAG,IAAI,EAAE,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAC1C,gBAAwB,EACxB,YAAoB;IAEpB,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,wCAAwC,CAAC,EAAE,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAW,kBAAkB,CACvC,gBAAgB,CAAC,KAAK,CAAC,wCAAwC,CAAC,MAAM,CAAC,CACxE,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,aAAa,GAAW,kBAAkB,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjF,OAAO,CACL,aAAa,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM,KAAK,aAAa;QACxB,MAAM,CAAC,UAAU,CAAC,GAAG,aAAa,GAAG,CAAC,CACvC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type OAuthProtectedResourceMetadataDetails } from "./protected-resource-metadata";
|
|
3
|
+
export interface OAuthProtectedResourceMetadataRouteOptions extends OAuthProtectedResourceMetadataDetails {
|
|
4
|
+
/**
|
|
5
|
+
* The resource identifier. Default: `SCHEMAVAULTS_RESOURCE_URL`, which
|
|
6
|
+
* `createSchemaVaultsAuthResolvers()` also accepts as a token audience;
|
|
7
|
+
* when you set it here instead, pass the same URL to their
|
|
8
|
+
* `acceptedAudiences`.
|
|
9
|
+
*/
|
|
10
|
+
readonly resource?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Issuer identifiers of the authorization servers. Default: the auth
|
|
13
|
+
* server URL (`SCHEMAVAULTS_AUTH_SERVER_URL`, or the environment's
|
|
14
|
+
* default auth server).
|
|
15
|
+
*/
|
|
16
|
+
readonly authorization_servers?: readonly string[];
|
|
17
|
+
/** Default: `getAppEnvironment()`, read per request. */
|
|
18
|
+
readonly environment?: SchemaVaultsAppEnvironment;
|
|
19
|
+
}
|
|
20
|
+
export type OAuthProtectedResourceMetadataRouteHandler = (request: Request) => Promise<Response>;
|
|
21
|
+
/**
|
|
22
|
+
* The OAuth 2.0 Protected Resource Metadata route (RFC 9728): tells
|
|
23
|
+
* OAuth clients (MCP clients, for one) which authorization server issues
|
|
24
|
+
* tokens for this resource server and which `resource` URL to request
|
|
25
|
+
* them for. In Next.js, `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`
|
|
26
|
+
* (the optional catch-all also answers the path-suffixed URLs of RFC 9728
|
|
27
|
+
* §3.1):
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* export const { GET, OPTIONS } = createOAuthProtectedResourceMetadataRoute({
|
|
31
|
+
* resource_name: "My API",
|
|
32
|
+
* resource_documentation: "/docs",
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* `GET` answers the document with `Access-Control-Allow-Origin: *` (it is
|
|
37
|
+
* public; browser-based clients read it cross-origin) and a one-hour
|
|
38
|
+
* cache; `OPTIONS` answers CORS preflights. Without a resource URL
|
|
39
|
+
* (`SCHEMAVAULTS_RESOURCE_URL` unset) the route answers 404: the server
|
|
40
|
+
* publishes no metadata. A path-suffixed request for a different resource
|
|
41
|
+
* is a 404 too; an invalid resource URL is a 500.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createOAuthProtectedResourceMetadataRoute(options?: OAuthProtectedResourceMetadataRouteOptions): {
|
|
44
|
+
GET: OAuthProtectedResourceMetadataRouteHandler;
|
|
45
|
+
OPTIONS: OAuthProtectedResourceMetadataRouteHandler;
|
|
46
|
+
};
|
|
47
|
+
export default createOAuthProtectedResourceMetadataRoute;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import getSchemaVaultsAuthServerUrl from "../env/get-schemavaults-auth-server-url";
|
|
2
|
+
import { RESOURCE_URL_ENV_VAR_NAME, getSchemaVaultsResourceUrl, parseResourceUrl, } from "../env/get-schemavaults-resource-url";
|
|
3
|
+
import { buildOAuthProtectedResourceMetadata, isMetadataRequestForResource, } from "./protected-resource-metadata";
|
|
4
|
+
const CORS_HEADERS = { "Access-Control-Allow-Origin": "*" };
|
|
5
|
+
function jsonResponse(status, body, cache_control) {
|
|
6
|
+
return new Response(JSON.stringify(body), {
|
|
7
|
+
status,
|
|
8
|
+
headers: {
|
|
9
|
+
...CORS_HEADERS,
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
"Cache-Control": cache_control,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function errorResponse(status, error, message) {
|
|
16
|
+
return jsonResponse(status, { error, message }, "no-store");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The OAuth 2.0 Protected Resource Metadata route (RFC 9728): tells
|
|
20
|
+
* OAuth clients (MCP clients, for one) which authorization server issues
|
|
21
|
+
* tokens for this resource server and which `resource` URL to request
|
|
22
|
+
* them for. In Next.js, `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`
|
|
23
|
+
* (the optional catch-all also answers the path-suffixed URLs of RFC 9728
|
|
24
|
+
* §3.1):
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* export const { GET, OPTIONS } = createOAuthProtectedResourceMetadataRoute({
|
|
28
|
+
* resource_name: "My API",
|
|
29
|
+
* resource_documentation: "/docs",
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* `GET` answers the document with `Access-Control-Allow-Origin: *` (it is
|
|
34
|
+
* public; browser-based clients read it cross-origin) and a one-hour
|
|
35
|
+
* cache; `OPTIONS` answers CORS preflights. Without a resource URL
|
|
36
|
+
* (`SCHEMAVAULTS_RESOURCE_URL` unset) the route answers 404: the server
|
|
37
|
+
* publishes no metadata. A path-suffixed request for a different resource
|
|
38
|
+
* is a 404 too; an invalid resource URL is a 500.
|
|
39
|
+
*/
|
|
40
|
+
export function createOAuthProtectedResourceMetadataRoute(options = {}) {
|
|
41
|
+
let warned_not_configured = false;
|
|
42
|
+
const GET = async (request) => {
|
|
43
|
+
let resource;
|
|
44
|
+
let authorization_servers;
|
|
45
|
+
try {
|
|
46
|
+
resource =
|
|
47
|
+
options.resource !== undefined
|
|
48
|
+
? parseResourceUrl(options.resource, options.environment)
|
|
49
|
+
: getSchemaVaultsResourceUrl(options.environment);
|
|
50
|
+
authorization_servers = options.authorization_servers ?? [getSchemaVaultsAuthServerUrl()];
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.error("[oauth-protected-resource] The protected resource metadata is misconfigured:", e);
|
|
54
|
+
return errorResponse(500, "server_misconfiguration", "The protected resource metadata of this server is misconfigured.");
|
|
55
|
+
}
|
|
56
|
+
if (resource === null) {
|
|
57
|
+
if (!warned_not_configured) {
|
|
58
|
+
warned_not_configured = true;
|
|
59
|
+
console.warn(`[oauth-protected-resource] '${RESOURCE_URL_ENV_VAR_NAME}' is not set; answering 404 to protected resource metadata requests.`);
|
|
60
|
+
}
|
|
61
|
+
return errorResponse(404, "not_found", "This server does not publish protected resource metadata.");
|
|
62
|
+
}
|
|
63
|
+
if (!isMetadataRequestForResource(new URL(request.url).pathname, resource)) {
|
|
64
|
+
return errorResponse(404, "not_found", "No protected resource is published at this path.");
|
|
65
|
+
}
|
|
66
|
+
return jsonResponse(200, buildOAuthProtectedResourceMetadata({ ...options, resource, authorization_servers }), "public, max-age=3600");
|
|
67
|
+
};
|
|
68
|
+
const OPTIONS = async (request) => {
|
|
69
|
+
const requested_headers = request.headers.get("Access-Control-Request-Headers");
|
|
70
|
+
return new Response(null, {
|
|
71
|
+
status: 204,
|
|
72
|
+
headers: {
|
|
73
|
+
...CORS_HEADERS,
|
|
74
|
+
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
|
75
|
+
...(requested_headers ? { "Access-Control-Allow-Headers": requested_headers } : {}),
|
|
76
|
+
"Access-Control-Max-Age": "86400",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return { GET, OPTIONS };
|
|
81
|
+
}
|
|
82
|
+
export default createOAuthProtectedResourceMetadataRoute;
|
|
83
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/oauth-protected-resource/route.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,MAAM,wCAAwC,CAAC;AAClF,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEL,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AAuBvC,MAAM,YAAY,GAAG,EAAE,6BAA6B,EAAE,GAAG,EAAW,CAAC;AAErE,SAAS,YAAY,CAAC,MAAc,EAAE,IAAa,EAAE,aAAqB;IACxE,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACxC,MAAM;QACN,OAAO,EAAE;YACP,GAAG,YAAY;YACf,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,aAAa;SAC/B;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,MAAiB,EAAE,KAAa,EAAE,OAAe;IACtE,OAAO,YAAY,CAAC,MAAM,EAAE,EAAE,K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CAAC;QAC7F,CAAC;QAED,OAAO,YAAY,CACjB,GAAG,EACH,mCAAmC,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC,EACpF,sBAAsB,CACvB,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,OAAO,GAA+C,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5E,MAAM,iBAAiB,GAAkB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC/F,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE;gBACP,GAAG,YAAY;gBACf,8BAA8B,EAAE,cAAc;gBAC9C,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnF,wBAAwB,EAAE,OAAO;aAClC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC;AAED,eAAe,yCAAyC,CAAC"}
|
|
@@ -27,7 +27,10 @@ export interface CreateSchemaVaultsAuthResolversOptions {
|
|
|
27
27
|
/**
|
|
28
28
|
* RFC 8707 resource URL(s) this resource server is known by; access
|
|
29
29
|
* tokens whose `aud` is one of them are accepted too. See
|
|
30
|
-
* `RouteGuardFactory`'s `accepted_audiences`.
|
|
30
|
+
* `RouteGuardFactory`'s `accepted_audiences`. The resource URL in
|
|
31
|
+
* `SCHEMAVAULTS_RESOURCE_URL` (the one the protected resource metadata
|
|
32
|
+
* route advertises), with or without a trailing slash, is always
|
|
33
|
+
* accepted in addition, read on first use.
|
|
31
34
|
*/
|
|
32
35
|
readonly acceptedAudiences?: readonly string[];
|
|
33
36
|
/**
|
|
@@ -89,8 +92,11 @@ export declare function bearerTokenFromAuthorizationHeader(header: string | unde
|
|
|
89
92
|
* auth server URL) is missing, the key is unusable, or the auth server
|
|
90
93
|
* refuses the JWKS download: a token is never waved through silently;
|
|
91
94
|
* - otherwise resolves `{ scheme, user, isAdmin: user.admin === true,
|
|
92
|
-
* scope, getOrganizationRole }`,
|
|
93
|
-
* auth server (`isUserInOrganization`
|
|
95
|
+
* scope, getOrganizationRole, listOrganizationMemberships }`, which ask
|
|
96
|
+
* the auth server (`isUserInOrganization` / `listUserOrganizations`)
|
|
97
|
+
* with the JWKS access key and forward the presented access token as
|
|
98
|
+
* the subject token, so an API server granted the `all_organizations`
|
|
99
|
+
* membership visibility can see the user's other organizations.
|
|
94
100
|
*
|
|
95
101
|
* Environment-derived settings are read on first use, not when the
|
|
96
102
|
* resolvers are created, so importing the module that builds them (e.g.
|
|
@@ -4,8 +4,10 @@ import { OperationError, schemaVaultsAccessTokenBearerScheme, } from "@schemavau
|
|
|
4
4
|
import { AccessTokenCookieName } from "../AccessTokenCookieNames";
|
|
5
5
|
import getSchemavaultsApiServerId from "../env/get-schemavaults-api-server-id";
|
|
6
6
|
import getSchemaVaultsAuthServerUrl from "../env/get-schemavaults-auth-server-url";
|
|
7
|
+
import { RESOURCE_URL_ENV_VAR_NAME, getSchemaVaultsResourceUrl, resourceUrlAudiences, } from "../env/get-schemavaults-resource-url";
|
|
7
8
|
import loadJwksAccessPrivateKey, { JWKS_ACCESS_PRIVATE_KEY_ENV_VAR_NAME, } from "../env/loadJwksAccessPrivateKey";
|
|
8
9
|
import isUserInOrganization from "../isUserInOrganization";
|
|
10
|
+
import listUserOrganizations from "../listUserOrganizations";
|
|
9
11
|
import { JwtKeyManagerMisconfigurationError } from "../JwtKeyManager/JwtKeyManagerMisconfigurationError";
|
|
10
12
|
import RouteGuardFactory from "../route_guards/route-guard-factory";
|
|
11
13
|
import { readCookie } from "./read-cookie";
|
|
@@ -98,8 +100,11 @@ export function bearerTokenFromAuthorizationHeader(header) {
|
|
|
98
100
|
* auth server URL) is missing, the key is unusable, or the auth server
|
|
99
101
|
* refuses the JWKS download: a token is never waved through silently;
|
|
100
102
|
* - otherwise resolves `{ scheme, user, isAdmin: user.admin === true,
|
|
101
|
-
* scope, getOrganizationRole }`,
|
|
102
|
-
* auth server (`isUserInOrganization`
|
|
103
|
+
* scope, getOrganizationRole, listOrganizationMemberships }`, which ask
|
|
104
|
+
* the auth server (`isUserInOrganization` / `listUserOrganizations`)
|
|
105
|
+
* with the JWKS access key and forward the presented access token as
|
|
106
|
+
* the subject token, so an API server granted the `all_organizations`
|
|
107
|
+
* membership visibility can see the user's other organizations.
|
|
103
108
|
*
|
|
104
109
|
* Environment-derived settings are read on first use, not when the
|
|
105
110
|
* resolvers are created, so importing the module that builds them (e.g.
|
|
@@ -158,12 +163,22 @@ export function createSchemaVaultsAuthResolvers(options = {}) {
|
|
|
158
163
|
const resolveFactory = () => {
|
|
159
164
|
if (factory === undefined) {
|
|
160
165
|
const env = resolveEnvironment();
|
|
166
|
+
let resourceUrl;
|
|
167
|
+
try {
|
|
168
|
+
resourceUrl = getSchemaVaultsResourceUrl(env);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
throw notConfigured(`the '${RESOURCE_URL_ENV_VAR_NAME}' environment variable is not a valid resource URL`, e);
|
|
172
|
+
}
|
|
161
173
|
try {
|
|
162
174
|
factory = new RouteGuardFactory({
|
|
163
175
|
environment: env,
|
|
164
176
|
jwt_keys_manager: keysManager,
|
|
165
177
|
is_token_revoked: options.isTokenRevoked,
|
|
166
|
-
accepted_audiences:
|
|
178
|
+
accepted_audiences: [
|
|
179
|
+
...(options.acceptedAudiences ?? []),
|
|
180
|
+
...(resourceUrl !== null ? resourceUrlAudiences(resourceUrl) : []),
|
|
181
|
+
],
|
|
167
182
|
debug,
|
|
168
183
|
});
|
|
169
184
|
}
|
|
@@ -229,6 +244,9 @@ export function createSchemaVaultsAuthResolvers(options = {}) {
|
|
|
229
244
|
message: "Your account is disabled",
|
|
230
245
|
});
|
|
231
246
|
}
|
|
247
|
+
// The token the user presented: forwarded to the auth server as the
|
|
248
|
+
// subject token of membership lookups.
|
|
249
|
+
const subject_token = source.token;
|
|
232
250
|
return {
|
|
233
251
|
scheme: scheme.name,
|
|
234
252
|
user,
|
|
@@ -238,8 +256,15 @@ export function createSchemaVaultsAuthResolvers(options = {}) {
|
|
|
238
256
|
const parsed = organizationIdSchema.safeParse(organizationId);
|
|
239
257
|
if (!parsed.success)
|
|
240
258
|
return false;
|
|
241
|
-
return isUserInOrganization(resolveAuthServerUrl(), audience, await resolveJwksAccessPrivateKey(), user.uid, parsed.data);
|
|
259
|
+
return isUserInOrganization(resolveAuthServerUrl(), audience, await resolveJwksAccessPrivateKey(), user.uid, parsed.data, { subject_token });
|
|
242
260
|
},
|
|
261
|
+
listOrganizationMemberships: async () => listUserOrganizations({
|
|
262
|
+
auth_server_url: resolveAuthServerUrl(),
|
|
263
|
+
api_server_id: audience,
|
|
264
|
+
jwks_access_private_key: await resolveJwksAccessPrivateKey(),
|
|
265
|
+
uid: user.uid,
|
|
266
|
+
subject_token,
|
|
267
|
+
}),
|
|
243
268
|
};
|
|
244
269
|
}
|
|
245
270
|
/** `Authorization: Bearer <access token>` */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-schemavaults-auth-resolvers.js","sourceRoot":"","sources":["../../src/openapi-operations/create-schemavaults-auth-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"create-schemavaults-auth-resolvers.js","sourceRoot":"","sources":["../../src/openapi-operations/create-schemavaults-auth-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,oBAAoB,GAGrB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EACL,cAAc,EACd,mCAAmC,GAMpC,MAAM,kCAAkC,CAAC;AAC1C,OAA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AA4C,CAAC,EAAE,MAAM;KACvD,CAAC;AACJ,CAAC;AAED,eAAe,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-server-sdk",
|
|
3
3
|
"description": "TypeScript SDK for building authenticated endpoints/middlewares for the Auth Server and Resource Servers",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.35.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"zod": "4.4.3",
|
|
21
|
-
"@schemavaults/jwt": "0.14.
|
|
22
|
-
"@schemavaults/auth-common": "0.33.
|
|
23
|
-
"@schemavaults/app-definitions": "0.
|
|
21
|
+
"@schemavaults/jwt": "0.14.7",
|
|
22
|
+
"@schemavaults/auth-common": "0.33.2",
|
|
23
|
+
"@schemavaults/app-definitions": "0.15.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json && bun run copy-codegen-templates && bun run prepare-cli",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "8.48.1",
|
|
47
47
|
"@typescript-eslint/parser": "8.48.1",
|
|
48
48
|
"esbuild": "0.27.3",
|
|
49
|
-
"@schemavaults/openapi-operations": "0.
|
|
49
|
+
"@schemavaults/openapi-operations": "0.5.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -162,10 +162,15 @@
|
|
|
162
162
|
"types": "./dist/auth-session-route/index.d.ts",
|
|
163
163
|
"import": "./dist/auth-session-route/index.js",
|
|
164
164
|
"require": "./dist/auth-session-route/index.js"
|
|
165
|
+
},
|
|
166
|
+
"./oauth-protected-resource": {
|
|
167
|
+
"types": "./dist/oauth-protected-resource/index.d.ts",
|
|
168
|
+
"import": "./dist/oauth-protected-resource/index.js",
|
|
169
|
+
"require": "./dist/oauth-protected-resource/index.js"
|
|
165
170
|
}
|
|
166
171
|
},
|
|
167
172
|
"peerDependencies": {
|
|
168
|
-
"@schemavaults/openapi-operations": "0.
|
|
173
|
+
"@schemavaults/openapi-operations": "0.5.0"
|
|
169
174
|
},
|
|
170
175
|
"peerDependenciesMeta": {
|
|
171
176
|
"@schemavaults/openapi-operations": {
|