@plasgos/oidc-client 0.0.0-stage → 0.1.0-next.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/CHANGELOG.md +21 -0
- package/LICENSE +14 -0
- package/README.md +136 -2
- package/dist/index.cjs +884 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +860 -0
- package/dist/index.js.map +1 -0
- package/dist/service.cjs +432 -0
- package/dist/service.cjs.map +1 -0
- package/dist/service.d.cts +88 -0
- package/dist/service.d.ts +88 -0
- package/dist/service.js +419 -0
- package/dist/service.js.map +1 -0
- package/dist/session.cjs +601 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +289 -0
- package/dist/session.d.ts +289 -0
- package/dist/session.js +568 -0
- package/dist/session.js.map +1 -0
- package/dist/types-Cncksfeo.d.cts +375 -0
- package/dist/types-Cncksfeo.d.ts +375 -0
- package/package.json +66 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @plasgos/oidc-client
|
|
2
|
+
|
|
3
|
+
## 0.1.0-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e6cc65b: Paket dipublish ke npmjs.com sebagai paket publik dengan lisensi Plasgos (`SEE LICENSE IN LICENSE`), tidak lagi di GitHub Packages. Install tidak butuh token: `pnpm add @plasgos/oidc-client@<versi> --save-exact`. Versi `0.1.0-next.0` hanya pernah terbit di GitHub Packages; rilis npmjs dimulai dari versi ini.
|
|
8
|
+
- Updated dependencies [e6cc65b]
|
|
9
|
+
- @plasgos/auth-shared@0.1.0-next.1
|
|
10
|
+
|
|
11
|
+
## 0.1.0-next.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 725d338: Rilis awal `@plasgos/oidc-client`: `createOidcClient` (login, callback, refresh, `ensureFresh`, logout), `/session` (cookie tersegel yang kompatibel dengan shipping-v2 dan accounts-v2), dan `/service` (`client_credentials` dengan cache). Panduan: `docs/guides/memulai.md`, `login-web.md`, `server-ke-server.md`, `error.md`, `contoh-hitungcuan.md`, `contoh-plaslink.md`.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [251d392]
|
|
20
|
+
- Updated dependencies [725d338]
|
|
21
|
+
- @plasgos/auth-shared@0.1.0-next.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Hak Cipta (c) 2026 Plasgos. Seluruh hak dilindungi.
|
|
2
|
+
|
|
3
|
+
Perangkat lunak ini (paket npm @plasgos/oidc-client dan @plasgos/auth-shared beserta dokumentasinya) adalah
|
|
4
|
+
milik Plasgos dan disediakan HANYA untuk menghubungkan aplikasi ke layanan Plasgos (login Plasgos dan API
|
|
5
|
+
Plasgos) oleh pihak yang memiliki kredensial client resmi dari Plasgos, sesuai ketentuan layanan Plasgos.
|
|
6
|
+
|
|
7
|
+
Pemegang kredensial tersebut dan pengembang yang bekerja untuk mereka boleh memasang dan memanggil perangkat
|
|
8
|
+
lunak ini di aplikasi mereka untuk keperluan itu. Selain itu, tanpa izin tertulis Plasgos, dilarang menyalin,
|
|
9
|
+
mengubah, menggabungkan, menerbitkan ulang, mendistribusikan, mensublisensikan, menjual, atau membuat karya
|
|
10
|
+
turunan dari perangkat lunak ini, seluruhnya maupun sebagian.
|
|
11
|
+
|
|
12
|
+
PERANGKAT LUNAK INI DISEDIAKAN "SEBAGAIMANA ADANYA", TANPA JAMINAN APA PUN. DALAM KEADAAN APA PUN PLASGOS
|
|
13
|
+
TIDAK BERTANGGUNG JAWAB ATAS KLAIM, KERUSAKAN, ATAU KEWAJIBAN LAIN YANG TIMBUL DARI ATAU BERKAITAN DENGAN
|
|
14
|
+
PERANGKAT LUNAK INI ATAU PEMAKAIANNYA, KECUALI DIATUR LAIN DALAM PERJANJIAN LAYANAN.
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @plasgos/oidc-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Client OIDC Plasgos untuk server Node. Paket ini untuk aplikasi yang **meminta** token ke Plasgos:
|
|
4
|
+
|
|
5
|
+
- login user lewat browser (authorization code + PKCE);
|
|
6
|
+
- sesi login di cookie terenkripsi;
|
|
7
|
+
- token server-ke-server (`client_credentials`) untuk memanggil API Plasgos tanpa user.
|
|
8
|
+
|
|
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
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Paket ini ada di npmjs.com dan di-install tanpa token. Pakai nomor versi persis, karena versi yang terbit masih pre-release:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @plasgos/oidc-client@<versi> --save-exact
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Aturan versi, Docker, dan CI ada di [`docs/consumers.md`](../../docs/consumers.md).
|
|
20
|
+
|
|
21
|
+
## Lisensi
|
|
22
|
+
|
|
23
|
+
Bukan open source. Paket ini milik Plasgos dan hanya boleh dipakai untuk menghubungkan aplikasi ke layanan Plasgos oleh pemegang kredensial client resmi dari Plasgos. Lihat file `LICENSE` di paket ini.
|
|
24
|
+
|
|
25
|
+
## Isi paket
|
|
26
|
+
|
|
27
|
+
| Import | Untuk | Panduan |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `@plasgos/oidc-client` | Login user: `createOidcClient` | [`login-web.md`](../../docs/guides/login-web.md) |
|
|
30
|
+
| `@plasgos/oidc-client/session` | Cookie sesi tersegel: `createSessionStore` | [`login-web.md`](../../docs/guides/login-web.md) |
|
|
31
|
+
| `@plasgos/oidc-client/service` | Server ke server: `createServiceClient` | [`server-ke-server.md`](../../docs/guides/server-ke-server.md) |
|
|
32
|
+
|
|
33
|
+
Mulai dari [`docs/guides/memulai.md`](../../docs/guides/memulai.md): paket mana yang dipakai, env, sandbox dan production, scope, dan cara mendapat kredensial.
|
|
34
|
+
|
|
35
|
+
## Contoh
|
|
36
|
+
|
|
37
|
+
Setiap fungsi `create…` wajib menerima `environment: "sandbox" | "production"`. Nilai ini pengaman, bukan pemilih URL: aplikasi menolak start bila `environment` tidak cocok dengan URL yang diberikan.
|
|
38
|
+
|
|
39
|
+
### `@plasgos/oidc-client`: login user
|
|
40
|
+
|
|
41
|
+
<!-- snippet: examples/snippets/readme.ts#login -->
|
|
42
|
+
```ts
|
|
43
|
+
export function createClient(): OidcClient {
|
|
44
|
+
return createOidcClient({
|
|
45
|
+
environment: "production",
|
|
46
|
+
issuer: "https://accounts.plasgos.co.id",
|
|
47
|
+
clientId: process.env.PLASGOS_LOGIN_CLIENT_ID ?? "",
|
|
48
|
+
clientSecret: process.env.PLASGOS_LOGIN_CLIENT_SECRET ?? "",
|
|
49
|
+
redirectUri: "https://app.example.com/auth/callback",
|
|
50
|
+
scopes: ["openid", "profile", "email"],
|
|
51
|
+
profile: "third-party",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** GET /login: redirects the browser to Plasgos. */
|
|
56
|
+
export function login(client: OidcClient, store: SessionStore<object>): Response {
|
|
57
|
+
const { location, transaction } = client.startLogin({ returnTo: "/" });
|
|
58
|
+
const headers = { Location: location, "Set-Cookie": store.commitTransaction(transaction) };
|
|
59
|
+
return new Response(null, { status: 302, headers });
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
<!-- /snippet -->
|
|
63
|
+
|
|
64
|
+
Client mengembalikan `startLogin`, `handleCallback`, `refresh`, `ensureFresh`, dan `logout`. Route callback dan logout yang lengkap ada di [`login-web.md`](../../docs/guides/login-web.md).
|
|
65
|
+
|
|
66
|
+
### `@plasgos/oidc-client/session`: cookie sesi
|
|
67
|
+
|
|
68
|
+
<!-- snippet: examples/snippets/readme.ts#session -->
|
|
69
|
+
```ts
|
|
70
|
+
export function createStore(): SessionStore<object> {
|
|
71
|
+
return createSessionStore<object>({
|
|
72
|
+
environment: "production",
|
|
73
|
+
secrets: [process.env.SESSION_SECRET ?? ""],
|
|
74
|
+
hkdfSalt: "app-example",
|
|
75
|
+
cookies: { app: "ax", auth: "ax-auth", idToken: "ax-idt", transaction: "ax-oidc" },
|
|
76
|
+
authMaxAgeSeconds: 2_592_000,
|
|
77
|
+
// This app keeps no data of its own in the session, only the SDK's auth.
|
|
78
|
+
appSchema: { parse: () => ({}) },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The signed-in user of a request, or null. */
|
|
83
|
+
export function currentUser(store: SessionStore<object>, request: Request): SessionUser | null {
|
|
84
|
+
return store.read(request).data.auth?.user ?? null;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
<!-- /snippet -->
|
|
88
|
+
|
|
89
|
+
Sesi disegel dengan AES-256-GCM (kunci HKDF per cookie, nama cookie terikat sebagai AAD). Cookie yang rusak atau tidak bisa dibuka dianggap tidak ada, tidak pernah menjadi error. Format cookie kompatibel dengan cookie plasgos-shipping-v2 dan plasgos-accounts-v2 yang sudah beredar.
|
|
90
|
+
|
|
91
|
+
### `@plasgos/oidc-client/service`: server ke server
|
|
92
|
+
|
|
93
|
+
<!-- snippet: examples/snippets/readme.ts#service -->
|
|
94
|
+
```ts
|
|
95
|
+
export async function whoAmI(): Promise<unknown> {
|
|
96
|
+
const plasgos = createServiceClient({
|
|
97
|
+
environment: "production",
|
|
98
|
+
issuer: "https://accounts.plasgos.co.id",
|
|
99
|
+
apiUrl: "https://api.plasgos.co.id",
|
|
100
|
+
clientId: process.env.PLASGOS_SERVICE_CLIENT_ID ?? "",
|
|
101
|
+
clientSecret: process.env.PLASGOS_SERVICE_CLIENT_SECRET ?? "",
|
|
102
|
+
scopes: ["platform:self.read"],
|
|
103
|
+
});
|
|
104
|
+
const res = await plasgos.fetch("/v5/service/me");
|
|
105
|
+
return res.json();
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
<!-- /snippet -->
|
|
109
|
+
|
|
110
|
+
Token disimpan di memori dan diminta lagi saat hampir habis. `fetch` mengulang satu kali bila API menjawab `401 invalid_token`, dan tidak mengikuti redirect.
|
|
111
|
+
|
|
112
|
+
## Daftar export
|
|
113
|
+
|
|
114
|
+
| Import | Fungsi dan nilai | Type |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `@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` |
|
|
118
|
+
| `@plasgos/oidc-client/service` | `createServiceClient`, `OidcError`, `ConfigError` | `ServiceClient`, `ServiceClientOptions`, `ServiceScope`, `OidcFailureEvent`, `OidcOperation`, `OidcFetch`, `OidcErrorReason`, `OidcUpstream`, `Environment` |
|
|
119
|
+
|
|
120
|
+
Setiap export punya JSDoc dengan contoh.
|
|
121
|
+
|
|
122
|
+
## Kegagalan
|
|
123
|
+
|
|
124
|
+
- Opsi yang salah: `ConfigError` saat `create…` dipanggil, memuat semua masalah sekaligus. `ConfigError` diekspor oleh ketiga entry, jadi `error instanceof ConfigError` bekerja bila kelasnya di-import dari `@plasgos/oidc-client`. Aplikasi yang mencampur `import` dan `require` memeriksa `error.name`.
|
|
125
|
+
- Kegagalan saat berjalan: `OidcError` dengan `reason`.
|
|
126
|
+
- Paket tidak pernah menulis log. Setiap kegagalan diserahkan ke hook `onFailure` milik aplikasi.
|
|
127
|
+
- Pesan error dan event tidak pernah memuat token, code, secret, atau isi cookie.
|
|
128
|
+
|
|
129
|
+
Arti setiap `reason`, penyebab umum, dan penanganannya ada di [`error.md`](../../docs/guides/error.md).
|
|
130
|
+
|
|
131
|
+
## Panduan
|
|
132
|
+
|
|
133
|
+
- [`memulai.md`](../../docs/guides/memulai.md): mulai dari sini
|
|
134
|
+
- [`login-web.md`](../../docs/guides/login-web.md): login user di aplikasi web
|
|
135
|
+
- [`server-ke-server.md`](../../docs/guides/server-ke-server.md): memanggil API Plasgos dari server
|
|
136
|
+
- [`error.md`](../../docs/guides/error.md): semua error dan `reason`
|
|
137
|
+
- [`contoh-hitungcuan.md`](../../docs/guides/contoh-hitungcuan.md), [`contoh-plaslink.md`](../../docs/guides/contoh-plaslink.md): contoh lengkap
|