@udibo/oauth2 0.33.0 → 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/dist/adapters/hono/bff/_cookie-keys.d.ts +17 -0
- package/dist/adapters/hono/bff/_cookie-keys.js +25 -0
- package/dist/adapters/hono/bff/auth-request-store.d.ts +22 -8
- package/dist/adapters/hono/bff/auth-request-store.js +29 -13
- package/dist/adapters/hono/bff/session-store.d.ts +14 -6
- package/dist/adapters/hono/bff/session-store.js +13 -11
- package/dist/cli/idp/server.js +2 -1
- package/dist/server/authorization-server.d.ts +32 -2
- package/dist/server/authorization-server.js +21 -2
- package/dist/server/grants/authorization-code.d.ts +56 -5
- package/dist/server/grants/authorization-code.js +97 -21
- package/dist/server/services/token.d.ts +51 -9
- package/dist/testing/contract/code-exchange.d.ts +100 -0
- package/dist/testing/contract/code-exchange.js +309 -0
- package/dist/testing/contract/mod.d.ts +6 -0
- package/dist/testing/contract/mod.js +6 -0
- package/dist/testing/contract/token.d.ts +8 -0
- package/dist/testing/contract/token.js +27 -0
- package/dist/testing/server.js +3 -2
- package/dist/testing/services.d.ts +23 -5
- package/dist/testing/services.js +40 -8
- package/dist/utils/crypto.d.ts +8 -26
- package/dist/utils/crypto.js +8 -33
- package/package.json +1 -1
package/dist/utils/crypto.js
CHANGED
|
@@ -2,20 +2,14 @@
|
|
|
2
2
|
* Authenticated-encryption (AES-256-GCM) and key-derivation helpers for sealing
|
|
3
3
|
* session and token data at rest or in a cookie.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* a high-entropy *per-session* secret yields an encryption key that is
|
|
14
|
-
* independent of any other value derived from the same secret. This is what
|
|
15
|
-
* makes "the cookie value is both the lookup credential **and** the decryption
|
|
16
|
-
* key" safe: a database can store `sha256(secret)` as a lookup hash while the
|
|
17
|
-
* sealing key is `HKDF(secret, info)`, and knowing the stored hash never
|
|
18
|
-
* reveals the key. Always pass a distinct `info` per purpose.
|
|
5
|
+
* {@link deriveSealKey} uses **HKDF** with a domain-separating `info` label so a
|
|
6
|
+
* high-entropy secret yields an encryption key that is independent of any other
|
|
7
|
+
* value derived from the same secret. This is what makes "the cookie value is
|
|
8
|
+
* both the lookup credential **and** the decryption key" safe: a database can
|
|
9
|
+
* store `sha256(secret)` as a lookup hash while the sealing key is
|
|
10
|
+
* `HKDF(secret, info)`, and knowing the stored hash never reveals the key. It is
|
|
11
|
+
* also what lets one secret seal two kinds of value without either opening as
|
|
12
|
+
* the other. Always pass a distinct `info` per purpose.
|
|
19
13
|
*
|
|
20
14
|
* {@link seal}/{@link unseal} use AES-256-GCM (an AEAD), so tampered ciphertext
|
|
21
15
|
* fails to unseal (returns `null`) rather than decrypting to garbage.
|
|
@@ -79,25 +73,6 @@ export function base64urlDecode(value) {
|
|
|
79
73
|
export function randomToken(bytes = 32) {
|
|
80
74
|
return base64urlEncode(crypto.getRandomValues(new Uint8Array(bytes)));
|
|
81
75
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Derive an AES-256-GCM key from a single server-held secret via SHA-256.
|
|
84
|
-
*
|
|
85
|
-
* Suitable when the secret is a long-lived configuration value that is never
|
|
86
|
-
* stored alongside the ciphertext. Do **not** use this when a hash of the same
|
|
87
|
-
* secret is persisted (e.g. as a lookup key) — use {@link deriveSealKey} so the
|
|
88
|
-
* sealing key is independent of that stored hash.
|
|
89
|
-
*
|
|
90
|
-
* @throws {Error} if the secret is shorter than 16 bytes. Length is all that is
|
|
91
|
-
* checked; supply 32+ bytes of real entropy.
|
|
92
|
-
*/
|
|
93
|
-
export async function deriveAesKey(secret) {
|
|
94
|
-
const raw = toBytes(secret);
|
|
95
|
-
if (raw.byteLength < 16) {
|
|
96
|
-
throw new Error("secret must be at least 16 bytes; 32+ bytes of entropy is recommended.");
|
|
97
|
-
}
|
|
98
|
-
const digest = await crypto.subtle.digest("SHA-256", toArrayBuffer(raw));
|
|
99
|
-
return await crypto.subtle.importKey("raw", digest, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
100
|
-
}
|
|
101
76
|
/**
|
|
102
77
|
* Derive an AES-256-GCM sealing key from a high-entropy secret via HKDF-SHA-256
|
|
103
78
|
* with a domain-separating `info` label.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@udibo/oauth2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "A flexible OAuth2 toolkit: framework-agnostic authorization & resource servers, a typed client, Hono adapters (including a backend-for-frontend), and React bindings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authorization-server",
|