@plasgos/oidc-client 0.1.0-next.2 → 0.1.0-next.3
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/CHANGELOG.md +17 -0
- package/README.md +7 -3
- package/dist/session.cjs +71 -20
- package/dist/session.cjs.map +1 -1
- package/dist/session.d.cts +55 -4
- package/dist/session.d.ts +55 -4
- package/dist/session.js +63 -13
- package/dist/session.js.map +1 -1
- package/docs/bff-express.md +1314 -0
- package/docs/consumers.md +10 -2
- package/docs/error.md +195 -10
- package/docs/examples/auth-verify-readme.ts +24 -0
- package/docs/examples/bff-express.ts +370 -0
- package/docs/examples/bff-proxy.ts +335 -0
- package/docs/examples/bff-redis-lock.ts +187 -0
- package/docs/examples/bff-revocation.ts +136 -0
- package/docs/examples/env.ts +52 -1
- package/docs/examples/token-commonjs.cjs +95 -0
- package/docs/examples/token-express.ts +56 -0
- package/docs/examples/token-fetch.ts +24 -0
- package/docs/examples/token-nestjs-jest.ts +77 -0
- package/docs/examples/token-nestjs.ts +127 -0
- package/docs/examples/token-socket.ts +59 -0
- package/docs/examples/token-testing.ts +100 -0
- package/docs/examples/token-verifier.ts +132 -0
- package/docs/examples/user-events.ts +110 -0
- package/docs/examples/webhook-verifier.ts +54 -0
- package/docs/login-web.md +39 -7
- package/docs/memulai.md +94 -14
- package/docs/server-ke-server.md +12 -0
- package/docs/verifikasi-token.md +1219 -0
- package/docs/webhook.md +191 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @plasgos/oidc-client
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ecc836b: Scope dan audience CRM: `crm:access` di `USER_SCOPES` dan `FIRST_PARTY_ONLY_SCOPES` (wajib bersama `resource`), `DEFAULT_AUDIENCES.crm` (`https://api.plasgos.co.id/crm`), dan tujuh scope service baru di `SERVICE_SCOPES` (`users:profile.read`, `users:legacy.read`, `packages:service.read`, `packages:service.write`, `subscriptions:catalog.write`, `subscriptions:read`, `subscriptions:grants.write`). `createOidcClient` kini menolak `crm:access` tanpa `resource` atau pada client pihak ketiga, dan menolak scope service baru di client login.
|
|
8
|
+
- cebfd60: Scope `phone` di `USER_SCOPES`: client login boleh memintanya (pihak pertama dan pihak ketiga), sedangkan `createServiceClient` menolaknya. Klaim `phone_number` dan `phone_number_verified` hanya dikirim bila nomor ponsel akun sudah terverifikasi. Pada login dengan `resource` klaim ada di ID token (dibaca lewat `extraClaims`); tanpa `resource` klaim diambil dari endpoint userinfo.
|
|
9
|
+
- f1b78dd: `createSessionStore` menerima opsi `path` (bawaan `"/"`). Dengan `"/"` tidak ada yang berubah (`__Host-`, `Path=/`). Dengan path lain, misalnya `"/crm/"`, nama cookie memakai `__Secure-` dan setiap cookie yang ditulis atau dihapus memakai `Path` itu, untuk BFF yang berjalan di bawah sub-path. Format cookie dan isi sesi tidak berubah, jadi cookie lama tetap terbaca. `readAccessTokenClaims` di `@plasgos/oidc-client/session` membaca `sid`, `cv`, dan `plasgos_public_id` dari access token milik sesi (tanpa verifikasi; hanya properti milik payload itu sendiri, bukan warisan prototype), untuk pemeriksaan pencabutan di BFF. Panduan `docs/login-web.md` dan `docs/error.md` diperbarui (ikut terbit di kedua paket).
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- da4ecca: Verifikasi access token Plasgos di API milik aplikasi: `createAccessTokenVerifier` (JWKS, RS256, `at+jwt`, `iss` dan `aud` persis, scope, klaim wajib lewat `requireClaims`, `maxAuthAge`, hook `isRevoked`; JWKS yang tidak bisa dibaca dijawab `503`), `@plasgos/auth-verify/express` (`requirePlasgosToken`), dan `@plasgos/auth-verify/nestjs` (`PlasgosAuthModule`, `PlasgosAccessTokenGuard`, `@RequireScopes`, `@RequireRecentAuth`, `@PlasgosPrincipal`; NestJS 11). Ketiganya menjawab penolakan dengan status, `Cache-Control: no-store`, `WWW-Authenticate` bila ada, dan body `{"error":"<errorCode>"}`; middleware Express meneruskan penolakan ke `next(error)` bila respons sudah terkirim atau tidak bisa ditulis, dan error lain yang hanya meminjam nama `AuthVerifyError` diperlakukan sebagai error biasa. Token untuk audience `crm` wajib membawa `cv`. Build CommonJS memuat `jose` di dalamnya, sehingga bisa dipakai aplikasi CommonJS dan Jest tanpa pengaturan tambahan. `AuthVerifyError` ada di `@plasgos/auth-shared`. Panduan baru `docs/verifikasi-token.md` dan `docs/bff-express.md`; `error.md`, `memulai.md`, dan `login-web.md` diperbarui (ikut terbit di kedua paket).
|
|
14
|
+
- e7f5278: `presets.appEvents` di `@plasgos/auth-verify/webhook`: preset untuk endpoint webhook aplikasi yang menerima event pembayaran, langganan, paket, dan user dengan satu secret. Header dan cara verifikasinya sama dengan `presets.payments`; hanya nama preset di hasil verifikasi yang berbeda. Panduan `docs/webhook.md` diperbarui (ikut terbit di kedua paket).
|
|
15
|
+
- Updated dependencies [da4ecca]
|
|
16
|
+
- Updated dependencies [ecc836b]
|
|
17
|
+
- Updated dependencies [cebfd60]
|
|
18
|
+
- @plasgos/auth-shared@0.1.0-next.3
|
|
19
|
+
|
|
3
20
|
## 0.1.0-next.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ Client OIDC Plasgos untuk server Node. Paket ini untuk aplikasi yang **meminta**
|
|
|
8
8
|
|
|
9
9
|
Hanya untuk server (Node `>=22.22`), tersedia sebagai ESM dan CommonJS. Tidak ada dependensi runtime selain `@plasgos/auth-shared`, yang ikut terpasang dengan versi yang sama.
|
|
10
10
|
|
|
11
|
+
**Link `@next`.** Link panduan di README ini (alamat `cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/…`) membuka pre-release yang ditunjuk tag `next` di npm, yang bisa lebih baru atau lebih lama dari versi yang Anda pasang. Untuk versi yang terpasang, baca `node_modules/@plasgos/oidc-client/docs/`.
|
|
12
|
+
|
|
11
13
|
## Install
|
|
12
14
|
|
|
13
15
|
Paket ini ada di npmjs.com dan di-install tanpa token. Pakai nomor versi persis, karena versi yang terbit masih pre-release:
|
|
@@ -27,7 +29,7 @@ Bukan open source. Paket ini milik Plasgos dan hanya boleh dipakai untuk menghub
|
|
|
27
29
|
| Import | Untuk | Panduan |
|
|
28
30
|
|---|---|---|
|
|
29
31
|
| `@plasgos/oidc-client` | Login user: `createOidcClient` | [`login-web.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/login-web.md) |
|
|
30
|
-
| `@plasgos/oidc-client/session` | Cookie sesi tersegel: `createSessionStore` | [`login-web.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/login-web.md) |
|
|
32
|
+
| `@plasgos/oidc-client/session` | Cookie sesi tersegel: `createSessionStore` (juga di bawah sub-path dengan `path`), `readAccessTokenClaims` | [`login-web.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/login-web.md) |
|
|
31
33
|
| `@plasgos/oidc-client/service` | Server ke server: `createServiceClient` | [`server-ke-server.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/server-ke-server.md) |
|
|
32
34
|
|
|
33
35
|
Mulai dari [`docs/memulai.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/memulai.md): paket mana yang dipakai, env, sandbox dan production, scope, dan cara mendapat kredensial. Daftar semua panduan ada di [Panduan](#panduan).
|
|
@@ -114,7 +116,7 @@ Token disimpan di memori dan diminta lagi saat hampir habis. `fetch` mengulang s
|
|
|
114
116
|
| Import | Fungsi dan nilai | Type |
|
|
115
117
|
|---|---|---|
|
|
116
118
|
| `@plasgos/oidc-client` | `createOidcClient`, `accessTokenExpiry`, `memoryLockStore`, `OidcError`, `ConfigError` | `OidcClient`, `OidcClientOptions`, `StartLoginInput`, `StartLoginResult`, `HandleCallbackOptions`, `CallbackResult`, `VerifiedIdTokenClaims`, `EnsureFreshOptions`, `EnsureFreshResult`, `RefreshableAuth`, `LogoutInput`, `LogoutResult`, `OidcTransaction`, `OidcFetch`, `RefreshLockStore`, `OidcFailureEvent`, `OidcOperation`, `OidcErrorReason`, `OidcUpstream`, `ClientProfile`, `Environment`, `IdTokenClaims`, `TokenSet`, `UserScope` |
|
|
117
|
-
| `@plasgos/oidc-client/session` | `createSessionStore`, `SessionTooLargeError`, `memoryLockStore`, `deriveKeyRing`, `sealCookie`, `openCookie`, `ConfigError` | `SessionStore`, `SessionStoreOptions`, `SessionHandle`, `SessionData`, `SessionSchema`, `SessionFailureEvent`, `AuthState`, `SessionUser`, `OidcTransaction`, `RefreshLockStore`, `KeyRing` |
|
|
119
|
+
| `@plasgos/oidc-client/session` | `createSessionStore` (dengan opsi `path` untuk aplikasi di bawah sub-path), `readAccessTokenClaims`, `SessionTooLargeError`, `memoryLockStore`, `deriveKeyRing`, `sealCookie`, `openCookie`, `ConfigError` | `SessionStore`, `SessionStoreOptions`, `SessionHandle`, `SessionData`, `SessionSchema`, `SessionFailureEvent`, `AuthState`, `SessionUser`, `AccessTokenSessionClaims`, `OidcTransaction`, `RefreshLockStore`, `KeyRing` |
|
|
118
120
|
| `@plasgos/oidc-client/service` | `createServiceClient`, `OidcError`, `ConfigError` | `ServiceClient`, `ServiceClientOptions`, `ServiceScope`, `OidcFailureEvent`, `OidcOperation`, `OidcFetch`, `OidcErrorReason`, `OidcUpstream`, `Environment` |
|
|
119
121
|
|
|
120
122
|
Setiap export punya JSDoc dengan contoh.
|
|
@@ -130,14 +132,16 @@ Arti setiap `reason`, penyebab umum, dan penanganannya ada di [`error.md`](https
|
|
|
130
132
|
|
|
131
133
|
## Panduan
|
|
132
134
|
|
|
133
|
-
Panduan pemakaian (Bahasa Indonesia) ikut di paket ini, di folder `docs/`. Link di bawah membuka pre-release
|
|
135
|
+
Panduan pemakaian (Bahasa Indonesia) ikut di paket ini, di folder `docs/`. Link di bawah membuka pre-release yang ditunjuk tag `next` secara online (jsDelivr). Untuk versi yang Anda pasang, bacanya di `node_modules/@plasgos/oidc-client/docs/`, atau di tab **Code** halaman paket di npmjs.com.
|
|
134
136
|
|
|
135
137
|
| Panduan | Untuk apa |
|
|
136
138
|
|---|---|
|
|
137
139
|
| [`memulai.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/memulai.md) | Mulai dari sini: paket mana untuk kebutuhan apa, env, sandbox dan production, scope, cara mendapat kredensial |
|
|
138
140
|
| [`login-web.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/login-web.md) | Login user di aplikasi web: route login, callback, logout, sesi cookie, refresh |
|
|
141
|
+
| [`bff-express.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/bff-express.md) | BFF Node/Express untuk SPA atau PWA: lock refresh Redis, sub-path, pencabutan sesi, proxy API dan socket, CSRF |
|
|
139
142
|
| [`server-ke-server.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/server-ke-server.md) | Memanggil API Plasgos dari server tanpa user (`client_credentials`), contoh payments |
|
|
140
143
|
| [`webhook.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/webhook.md) | Menerima webhook dari Plasgos dengan `@plasgos/auth-verify/webhook` |
|
|
144
|
+
| [`verifikasi-token.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/verifikasi-token.md) | Memeriksa access token Plasgos di API sendiri dengan `@plasgos/auth-verify` (Express, NestJS, `Request`) |
|
|
141
145
|
| [`error.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/error.md) | Semua error dan `reason`: arti, penyebab umum, penanganan |
|
|
142
146
|
| [`contoh-hitungcuan.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/contoh-hitungcuan.md) | Contoh lengkap aplikasi yang hanya memakai payments |
|
|
143
147
|
| [`contoh-plaslink.md`](https://cdn.jsdelivr.net/npm/@plasgos/oidc-client@next/docs/contoh-plaslink.md) | Contoh lengkap login seller dan payments |
|
package/dist/session.cjs
CHANGED
|
@@ -20,16 +20,48 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/session/index.ts
|
|
21
21
|
var session_exports = {};
|
|
22
22
|
__export(session_exports, {
|
|
23
|
-
ConfigError: () =>
|
|
23
|
+
ConfigError: () => import_auth_shared3.ConfigError,
|
|
24
24
|
SessionTooLargeError: () => SessionTooLargeError,
|
|
25
25
|
createSessionStore: () => createSessionStore,
|
|
26
26
|
deriveKeyRing: () => deriveKeyRing,
|
|
27
27
|
memoryLockStore: () => memoryLockStore,
|
|
28
28
|
openCookie: () => openCookie,
|
|
29
|
+
readAccessTokenClaims: () => readAccessTokenClaims,
|
|
29
30
|
sealCookie: () => sealCookie
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(session_exports);
|
|
32
33
|
|
|
34
|
+
// src/session/access-token-claims.ts
|
|
35
|
+
var import_auth_shared = require("@plasgos/auth-shared");
|
|
36
|
+
var SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
37
|
+
var MAX_PUBLIC_ID_LENGTH = 128;
|
|
38
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39
|
+
function readAccessTokenClaims(accessToken) {
|
|
40
|
+
const raw = accessToken;
|
|
41
|
+
if (typeof raw !== "string" || raw.length > import_auth_shared.MAX_JWT_LENGTH) return null;
|
|
42
|
+
const parts = raw.split(".");
|
|
43
|
+
if (parts.length !== 3) return null;
|
|
44
|
+
const [header = "", payload = ""] = parts;
|
|
45
|
+
if (!SEGMENT.test(header) || !SEGMENT.test(payload)) return null;
|
|
46
|
+
let claims;
|
|
47
|
+
try {
|
|
48
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.from(payload, "base64url"));
|
|
49
|
+
claims = JSON.parse(text);
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (!isRecord(claims)) return null;
|
|
54
|
+
const own2 = (name) => Object.hasOwn(claims, name) ? claims[name] : void 0;
|
|
55
|
+
const sid = own2("sid");
|
|
56
|
+
const cv = own2("cv");
|
|
57
|
+
const publicId = own2("plasgos_public_id");
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
sid: typeof sid === "string" && sid !== "" ? sid : null,
|
|
60
|
+
cv: typeof cv === "number" && Number.isSafeInteger(cv) ? cv : null,
|
|
61
|
+
plasgos_public_id: typeof publicId === "string" && publicId !== "" && publicId.length <= MAX_PUBLIC_ID_LENGTH ? publicId : null
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
33
65
|
// src/session/cookie-crypto.ts
|
|
34
66
|
var import_node_crypto = require("crypto");
|
|
35
67
|
var VERSION = "v1";
|
|
@@ -96,7 +128,7 @@ function openCookie(cookie, sealed, ring) {
|
|
|
96
128
|
}
|
|
97
129
|
|
|
98
130
|
// src/session/store.ts
|
|
99
|
-
var
|
|
131
|
+
var import_auth_shared2 = require("@plasgos/auth-shared");
|
|
100
132
|
|
|
101
133
|
// src/session/compact-keys.ts
|
|
102
134
|
var CORE_COMPACT_KEYS = Object.freeze({
|
|
@@ -184,10 +216,10 @@ function cookieValue(header, name) {
|
|
|
184
216
|
}
|
|
185
217
|
return null;
|
|
186
218
|
}
|
|
187
|
-
function serialize(name, value, maxAge, secure) {
|
|
219
|
+
function serialize(name, value, maxAge, secure, path = "/") {
|
|
188
220
|
const attrs = [`${name}=${value}`];
|
|
189
221
|
if (maxAge !== void 0) attrs.push(`Max-Age=${String(maxAge)}`);
|
|
190
|
-
attrs.push(
|
|
222
|
+
attrs.push(`Path=${path}`, "HttpOnly");
|
|
191
223
|
if (secure) attrs.push("Secure");
|
|
192
224
|
attrs.push("SameSite=Lax");
|
|
193
225
|
return attrs.join("; ");
|
|
@@ -237,7 +269,7 @@ function createSessionHandle(data, authDirty, restDirty) {
|
|
|
237
269
|
// src/session/parsers.ts
|
|
238
270
|
var TOKEN_MAX = 4096;
|
|
239
271
|
var TEXT_MAX = 512;
|
|
240
|
-
function
|
|
272
|
+
function isRecord2(value) {
|
|
241
273
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
242
274
|
}
|
|
243
275
|
var own = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
|
|
@@ -246,7 +278,7 @@ var isText = (value) => typeof value === "string" && value.length <= TEXT_MAX;
|
|
|
246
278
|
var isRequiredText = (value) => isText(value) && value.length >= 1;
|
|
247
279
|
var isCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
248
280
|
function parseUser(input) {
|
|
249
|
-
if (!
|
|
281
|
+
if (!isRecord2(input)) return null;
|
|
250
282
|
const id = own(input, "id");
|
|
251
283
|
const name = own(input, "name");
|
|
252
284
|
const email = own(input, "email");
|
|
@@ -257,7 +289,7 @@ function parseUser(input) {
|
|
|
257
289
|
return { id, name, ...email !== void 0 ? { email } : {}, avatar_url: avatar };
|
|
258
290
|
}
|
|
259
291
|
function parseAuthState(input) {
|
|
260
|
-
if (!
|
|
292
|
+
if (!isRecord2(input)) return null;
|
|
261
293
|
const accessToken = own(input, "access_token");
|
|
262
294
|
const refreshToken = own(input, "refresh_token");
|
|
263
295
|
const expiresAt = own(input, "expires_at");
|
|
@@ -278,19 +310,19 @@ function parseAuthState(input) {
|
|
|
278
310
|
};
|
|
279
311
|
}
|
|
280
312
|
function parseAuthPart(input) {
|
|
281
|
-
if (!
|
|
313
|
+
if (!isRecord2(input)) return null;
|
|
282
314
|
const raw = own(input, "auth");
|
|
283
315
|
if (raw === void 0) return {};
|
|
284
316
|
const auth = parseAuthState(raw);
|
|
285
317
|
return auth === null ? null : { auth };
|
|
286
318
|
}
|
|
287
319
|
function parseIdTokenPart(input) {
|
|
288
|
-
if (!
|
|
320
|
+
if (!isRecord2(input)) return null;
|
|
289
321
|
const idToken = own(input, "id_token");
|
|
290
322
|
return isToken(idToken) ? { id_token: idToken } : null;
|
|
291
323
|
}
|
|
292
324
|
function parseTransaction(input) {
|
|
293
|
-
if (!
|
|
325
|
+
if (!isRecord2(input)) return null;
|
|
294
326
|
const state = own(input, "state");
|
|
295
327
|
const nonce = own(input, "nonce");
|
|
296
328
|
const codeVerifier = own(input, "code_verifier");
|
|
@@ -319,6 +351,8 @@ var TRANSACTION_MAX_AGE_SECONDS = 600;
|
|
|
319
351
|
var CLOCK_SKEW_MS = 5e3;
|
|
320
352
|
var MIN_SECRET_BYTES = 32;
|
|
321
353
|
var COOKIE_NAME = /^[a-z0-9-]{1,32}$/;
|
|
354
|
+
var COOKIE_PATH = /^\/(?:[\x21-\x7E]*\/)?$/;
|
|
355
|
+
var PATH_PROBLEM = 'path must start and end with "/" and contain only printable ASCII without ";", ",", "%", ".." or "//"';
|
|
322
356
|
var ROLES = ["app", "auth", "idToken", "transaction"];
|
|
323
357
|
var SessionTooLargeError = class extends Error {
|
|
324
358
|
/** Length of the refused `Set-Cookie` value, in characters. */
|
|
@@ -332,12 +366,25 @@ var SessionTooLargeError = class extends Error {
|
|
|
332
366
|
};
|
|
333
367
|
var isPositiveInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
334
368
|
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
369
|
+
function readPath(problems, raw) {
|
|
370
|
+
if (raw === void 0) return "/";
|
|
371
|
+
if (typeof raw !== "string") {
|
|
372
|
+
problems.push("path must be a string");
|
|
373
|
+
return "/";
|
|
374
|
+
}
|
|
375
|
+
if (raw.trim() === "") return "/";
|
|
376
|
+
if (!COOKIE_PATH.test(raw) || /[;,%]/.test(raw) || raw.includes("..") || raw.includes("//")) {
|
|
377
|
+
problems.push(PATH_PROBLEM);
|
|
378
|
+
return "/";
|
|
379
|
+
}
|
|
380
|
+
return raw;
|
|
381
|
+
}
|
|
335
382
|
function readOptions(raw) {
|
|
336
|
-
if (!isObject(raw)) throw new
|
|
383
|
+
if (!isObject(raw)) throw new import_auth_shared2.ConfigError(["options must be an object"]);
|
|
337
384
|
const problems = [];
|
|
338
385
|
const { environment, hostPrefix, hkdfSalt, secrets, cookies, authMaxAgeSeconds } = raw;
|
|
339
|
-
const { appSchema, compactKeys, onFailure } = raw;
|
|
340
|
-
if (typeof environment !== "string" || !
|
|
386
|
+
const { appSchema, compactKeys, onFailure, path } = raw;
|
|
387
|
+
if (typeof environment !== "string" || !import_auth_shared2.ENVIRONMENTS.includes(environment)) {
|
|
341
388
|
problems.push('environment must be "sandbox" or "production"');
|
|
342
389
|
}
|
|
343
390
|
if (hostPrefix !== void 0 && typeof hostPrefix !== "boolean") {
|
|
@@ -345,6 +392,7 @@ function readOptions(raw) {
|
|
|
345
392
|
} else if (hostPrefix === false && environment === "production") {
|
|
346
393
|
problems.push('hostPrefix: false is not allowed when environment is "production"');
|
|
347
394
|
}
|
|
395
|
+
const cookiePath = readPath(problems, path);
|
|
348
396
|
if (hkdfSalt === void 0 || hkdfSalt === null || hkdfSalt === "") {
|
|
349
397
|
problems.push("hkdfSalt is required");
|
|
350
398
|
} else if (typeof hkdfSalt !== "string") {
|
|
@@ -376,12 +424,13 @@ function readOptions(raw) {
|
|
|
376
424
|
if (onFailure !== void 0 && typeof onFailure !== "function") {
|
|
377
425
|
problems.push("onFailure must be a function");
|
|
378
426
|
}
|
|
379
|
-
if (problems.length > 0) throw new
|
|
427
|
+
if (problems.length > 0) throw new import_auth_shared2.ConfigError(problems);
|
|
380
428
|
return {
|
|
381
429
|
secrets: secretList,
|
|
382
430
|
hkdfSalt,
|
|
383
431
|
cookies: names,
|
|
384
432
|
secure: hostPrefix !== false,
|
|
433
|
+
path: cookiePath,
|
|
385
434
|
authMaxAge: authMaxAgeSeconds,
|
|
386
435
|
parseApp: (input) => appSchema.parse(input),
|
|
387
436
|
compactKeys,
|
|
@@ -404,7 +453,7 @@ function withFallback(cookie, commit, drop, report) {
|
|
|
404
453
|
}
|
|
405
454
|
function createSessionStore(options) {
|
|
406
455
|
const settings = readOptions(options);
|
|
407
|
-
const { cookies, secure } = settings;
|
|
456
|
+
const { cookies, secure, path } = settings;
|
|
408
457
|
const codec = createKeyCodec(settings.compactKeys);
|
|
409
458
|
const ring = (role) => rings[role];
|
|
410
459
|
const rings = {
|
|
@@ -413,7 +462,8 @@ function createSessionStore(options) {
|
|
|
413
462
|
idToken: deriveKeyRing(settings.secrets, cookies.idToken, settings.hkdfSalt),
|
|
414
463
|
transaction: deriveKeyRing(settings.secrets, cookies.transaction, settings.hkdfSalt)
|
|
415
464
|
};
|
|
416
|
-
const
|
|
465
|
+
const prefix = !secure ? "" : path === "/" ? "__Host-" : "__Secure-";
|
|
466
|
+
const wireName = (role) => `${prefix}${cookies[role]}`;
|
|
417
467
|
const cookieNames = Object.freeze({
|
|
418
468
|
app: wireName("app"),
|
|
419
469
|
auth: wireName("auth"),
|
|
@@ -426,8 +476,8 @@ function createSessionStore(options) {
|
|
|
426
476
|
if (raw === null || raw === "") return null;
|
|
427
477
|
return openCookie(cookies[role], raw, ring(role));
|
|
428
478
|
};
|
|
429
|
-
const seal = (role, value, maxAge) => serialize(cookieNames[role], sealCookie(cookies[role], value, ring(role)), maxAge, secure);
|
|
430
|
-
const expire = (role) => serialize(cookieNames[role], "", 0, secure);
|
|
479
|
+
const seal = (role, value, maxAge) => serialize(cookieNames[role], sealCookie(cookies[role], value, ring(role)), maxAge, secure, path);
|
|
480
|
+
const expire = (role) => serialize(cookieNames[role], "", 0, secure, path);
|
|
431
481
|
const parseApp = (value) => {
|
|
432
482
|
let parsed;
|
|
433
483
|
try {
|
|
@@ -443,7 +493,7 @@ function createSessionStore(options) {
|
|
|
443
493
|
if (typeof setting === "number") return setting;
|
|
444
494
|
const seconds = setting(auth);
|
|
445
495
|
if (!isPositiveInteger(seconds)) {
|
|
446
|
-
throw new
|
|
496
|
+
throw new import_auth_shared2.ConfigError(["authMaxAgeSeconds must return a positive integer"]);
|
|
447
497
|
}
|
|
448
498
|
return seconds;
|
|
449
499
|
};
|
|
@@ -587,7 +637,7 @@ function memoryLockStore(options = {}) {
|
|
|
587
637
|
}
|
|
588
638
|
|
|
589
639
|
// src/session/index.ts
|
|
590
|
-
var
|
|
640
|
+
var import_auth_shared3 = require("@plasgos/auth-shared");
|
|
591
641
|
// Annotate the CommonJS export names for ESM import in node:
|
|
592
642
|
0 && (module.exports = {
|
|
593
643
|
ConfigError,
|
|
@@ -596,6 +646,7 @@ var import_auth_shared2 = require("@plasgos/auth-shared");
|
|
|
596
646
|
deriveKeyRing,
|
|
597
647
|
memoryLockStore,
|
|
598
648
|
openCookie,
|
|
649
|
+
readAccessTokenClaims,
|
|
599
650
|
sealCookie
|
|
600
651
|
});
|
|
601
652
|
//# sourceMappingURL=session.cjs.map
|