@schemavaults/auth-server-sdk 0.41.2 → 0.42.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.
- package/README.md +9 -0
- package/dist/auth-session-route/index.d.ts +1 -0
- package/dist/auth-session-route/index.js.map +1 -1
- package/dist/auth-session-route/token-route.d.ts +15 -2
- package/dist/auth-session-route/token-route.js +16 -3
- package/dist/auth-session-route/token-route.js.map +1 -1
- package/dist/cli.cjs +5 -2
- package/dist/codegen-templates/auth/auth-provider.tsx +9 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -168,6 +168,15 @@ app's `authorization_code` and `refresh_token` grants.
|
|
|
168
168
|
The auth server rate-limits refresh grants per IP; proxied through the token
|
|
169
169
|
route, they count against the app server's IP.
|
|
170
170
|
|
|
171
|
+
An app with a client secret is a confidential client: the auth server then
|
|
172
|
+
refuses every token request of the app that does not authenticate with the
|
|
173
|
+
secret, its users' sign-ins included. Set `SCHEMAVAULTS_CLIENT_SECRET` (or
|
|
174
|
+
pass `client_secret` to `createAuthSessionTokenRoute()`) and the token route
|
|
175
|
+
authenticates the code and refresh grants it forwards with it
|
|
176
|
+
(`client_secret_basic`); the secret never reaches the browser. That is how an
|
|
177
|
+
app whose backend mints delegated tokens for its agents (below) keeps signing
|
|
178
|
+
its users in through these routes.
|
|
179
|
+
|
|
171
180
|
## Accepting resource-URL token audiences
|
|
172
181
|
|
|
173
182
|
Access tokens are normally minted with your API server id as their `aud`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createAuthSessionTokenRoute } from "./token-route";
|
|
2
|
+
export type { AuthSessionTokenRouteOptions } from "./token-route";
|
|
2
3
|
export { createAuthSessionWhoamiRoute } from "./whoami-route";
|
|
3
4
|
export { createAuthSessionLogoutRoute } from "./logout-route";
|
|
4
5
|
export type { AuthSessionRouteHandler, AuthSessionRouteOptions, AuthSessionUpstreamFetch, } from "./session-route-context";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth-session-route/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth-session-route/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { type AuthSessionRouteHandler, type AuthSessionRouteOptions } from "./session-route-context";
|
|
2
|
+
export interface AuthSessionTokenRouteOptions extends AuthSessionRouteOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The app's client secret, when it is a confidential client (e.g. its
|
|
5
|
+
* backend exchanges its users' tokens for its agents' delegated tokens):
|
|
6
|
+
* the route then authenticates the code and refresh grants it forwards
|
|
7
|
+
* with it (`client_secret_basic`), which the auth server requires of every
|
|
8
|
+
* token request of an app with a secret. It never reaches the browser.
|
|
9
|
+
* Default: `SCHEMAVAULTS_CLIENT_SECRET`; unset, the app is a public client.
|
|
10
|
+
*/
|
|
11
|
+
client_secret?: string;
|
|
12
|
+
}
|
|
2
13
|
/**
|
|
3
14
|
* The token session route (`POST`): the SDK's authorization code and refresh grants.
|
|
4
15
|
* Forwarded to the auth server's token endpoint; the refresh token goes into
|
|
5
16
|
* the session cookie (a refresh grant presents the cookie's), never into the
|
|
6
|
-
* response body.
|
|
17
|
+
* response body. A confidential client's grants are authenticated with its
|
|
18
|
+
* client secret (`client_secret`, default `SCHEMAVAULTS_CLIENT_SECRET`). In
|
|
19
|
+
* Next.js, `app/auth/session/token/route.ts`:
|
|
7
20
|
*
|
|
8
21
|
* ```ts
|
|
9
22
|
* export const { POST } = createAuthSessionTokenRoute();
|
|
10
23
|
* ```
|
|
11
24
|
*/
|
|
12
|
-
export declare function createAuthSessionTokenRoute(options?:
|
|
25
|
+
export declare function createAuthSessionTokenRoute(options?: AuthSessionTokenRouteOptions): {
|
|
13
26
|
POST: AuthSessionRouteHandler;
|
|
14
27
|
};
|
|
15
28
|
export default createAuthSessionTokenRoute;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { MaximumBrowserCookieSize, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, getOidcEndpointUrl, } from "@schemavaults/auth-common";
|
|
2
2
|
import getStringByteSize from "../getStringByteSize";
|
|
3
|
+
import { clientSecretBasicAuthorization } from "../confidential-client/shared";
|
|
3
4
|
import { serializeClearedSessionCookie, serializeSessionCookie } from "./session-cookie";
|
|
4
5
|
import { createSessionRoute, json, } from "./session-route-context";
|
|
5
6
|
function oauthError(status, error, error_description) {
|
|
6
7
|
return json(status, { error, error_description });
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** The configured client secret (read per request: env vars may be unset at build time). */
|
|
10
|
+
function resolveClientSecret(options) {
|
|
11
|
+
const client_secret = options.client_secret ?? process.env.SCHEMAVAULTS_CLIENT_SECRET;
|
|
12
|
+
return typeof client_secret === "string" && client_secret.length > 0 ? client_secret : null;
|
|
13
|
+
}
|
|
14
|
+
async function handleToken({ request, config, cookie, refresh_token, callAuthServer }, client_secret) {
|
|
9
15
|
const form = new URLSearchParams(await request.text());
|
|
10
16
|
if (form.get("client_id") !== config.client_app_id) {
|
|
11
17
|
return oauthError(400, "invalid_client", "This session route serves another client.");
|
|
@@ -34,6 +40,9 @@ async function handleToken({ request, config, cookie, refresh_token, callAuthSer
|
|
|
34
40
|
const origin = request.headers.get("origin");
|
|
35
41
|
if (origin)
|
|
36
42
|
headers.set("Origin", origin);
|
|
43
|
+
if (client_secret) {
|
|
44
|
+
headers.set("Authorization", clientSecretBasicAuthorization({ client_id: config.client_app_id, client_secret }));
|
|
45
|
+
}
|
|
37
46
|
let upstream;
|
|
38
47
|
let body;
|
|
39
48
|
try {
|
|
@@ -77,14 +86,18 @@ async function handleToken({ request, config, cookie, refresh_token, callAuthSer
|
|
|
77
86
|
* The token session route (`POST`): the SDK's authorization code and refresh grants.
|
|
78
87
|
* Forwarded to the auth server's token endpoint; the refresh token goes into
|
|
79
88
|
* the session cookie (a refresh grant presents the cookie's), never into the
|
|
80
|
-
* response body.
|
|
89
|
+
* response body. A confidential client's grants are authenticated with its
|
|
90
|
+
* client secret (`client_secret`, default `SCHEMAVAULTS_CLIENT_SECRET`). In
|
|
91
|
+
* Next.js, `app/auth/session/token/route.ts`:
|
|
81
92
|
*
|
|
82
93
|
* ```ts
|
|
83
94
|
* export const { POST } = createAuthSessionTokenRoute();
|
|
84
95
|
* ```
|
|
85
96
|
*/
|
|
86
97
|
export function createAuthSessionTokenRoute(options = {}) {
|
|
87
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
POST: createSessionRoute(options, (route) => handleToken(route, resolveClientSecret(options))),
|
|
100
|
+
};
|
|
88
101
|
}
|
|
89
102
|
export default createAuthSessionTokenRoute;
|
|
90
103
|
//# sourceMappingURL=token-route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-route.js","sourceRoot":"","sources":["../../src/auth-session-route/token-route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uCAAuC,EACvC,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAIL,kBAAkB,EAClB,IAAI,GACL,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"token-route.js","sourceRoot":"","sources":["../../src/auth-session-route/token-route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uCAAuC,EACvC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AM,CACrB,YAAY,EACZ,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CACpF,CAAC;IACJ,CAAC;SAAM,IAAI,UAAU,KAAK,eAAe,IAAI,IAAI,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;QAC5E,gBAAgB,CAAC,MAAM,CAAC,YAAY,EAAE,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAwC,EAAE;IAE1C,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;KAC/F,CAAC;AACJ,CAAC;AAED,eAAe,2BAA2B,CAAC"}
|
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 version2 = true ? "0.
|
|
92
|
+
const version2 = true ? "0.42.1" : "unknown";
|
|
93
93
|
return `${CODEGEN_MARKER_PREFIX}${version2}`;
|
|
94
94
|
}
|
|
95
95
|
function hasCodegenMarker(firstLine) {
|
|
@@ -21001,6 +21001,9 @@ var updateAppApiScopePolicyRequestSchema = external_exports.object({
|
|
|
21001
21001
|
user_scopes: scopeValueListSchema,
|
|
21002
21002
|
service_account_scopes: scopeValueListSchema
|
|
21003
21003
|
}).strict();
|
|
21004
|
+
var appApiConnectionFirstPartySchema = external_exports.object({
|
|
21005
|
+
first_party: external_exports.boolean()
|
|
21006
|
+
}).strict();
|
|
21004
21007
|
|
|
21005
21008
|
// ../auth-common/dist/api-scopes/consent.js
|
|
21006
21009
|
var consentScopeSchema = external_exports.object({
|
|
@@ -23384,7 +23387,7 @@ async function main() {
|
|
|
23384
23387
|
return;
|
|
23385
23388
|
}
|
|
23386
23389
|
if (args.includes("--version") || args.includes("-v")) {
|
|
23387
|
-
console.log(`${PACKAGE_NAME}@${"0.
|
|
23390
|
+
console.log(`${PACKAGE_NAME}@${"0.42.1"}`);
|
|
23388
23391
|
return;
|
|
23389
23392
|
}
|
|
23390
23393
|
const command = findCommand(args, FLAGS_WITH_VALUES) ?? "codegen";
|
|
@@ -24,6 +24,14 @@ export interface IAppAuthProviderProps extends PropsWithChildren {
|
|
|
24
24
|
*/
|
|
25
25
|
auth_server_url?: string;
|
|
26
26
|
default_audiences: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* The authorization request every sign-in makes, e.g. your API's scopes:
|
|
29
|
+
* `{ scope: "openid email profile notes:read", resource: "my-notes-api" }`
|
|
30
|
+
* (see `SchemaVaultsAuthProviderProps.authorization_params`). Sessions
|
|
31
|
+
* whose sign-in asked for less are sent through the flow again. Define it
|
|
32
|
+
* at module level so it stays stable.
|
|
33
|
+
*/
|
|
34
|
+
authorization_params?: SchemaVaultsAuthProviderProps["authorization_params"];
|
|
27
35
|
debug?: boolean;
|
|
28
36
|
authed_on_unauthed_redirect_uri: string;
|
|
29
37
|
unauthed_on_authed_redirect_uri: string;
|
|
@@ -76,6 +84,7 @@ export default function AppAuthProvider({
|
|
|
76
84
|
router={router}
|
|
77
85
|
path={path}
|
|
78
86
|
default_audiences={props.default_audiences}
|
|
87
|
+
authorization_params={props.authorization_params}
|
|
79
88
|
autoreacquire_access_tokens={
|
|
80
89
|
typeof props.autoreacquire_access_tokens === "boolean"
|
|
81
90
|
? props.autoreacquire_access_tokens
|
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.42.1",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"zod": "4.6.7",
|
|
21
|
-
"@schemavaults/jwt": "0.17.
|
|
22
|
-
"@schemavaults/auth-common": "0.
|
|
21
|
+
"@schemavaults/jwt": "0.17.1",
|
|
22
|
+
"@schemavaults/auth-common": "0.39.0",
|
|
23
23
|
"@schemavaults/app-definitions": "0.17.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
@@ -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.7.
|
|
49
|
+
"@schemavaults/openapi-operations": "0.7.1"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
182
|
"peerDependencies": {
|
|
183
|
-
"@schemavaults/openapi-operations": "0.7.
|
|
183
|
+
"@schemavaults/openapi-operations": "0.7.1"
|
|
184
184
|
},
|
|
185
185
|
"peerDependenciesMeta": {
|
|
186
186
|
"@schemavaults/openapi-operations": {
|