@keycardai/oauth 0.6.0 → 0.8.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/LICENSE +5 -17
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/pkce.d.ts +4 -0
- package/dist/cjs/pkce.d.ts.map +1 -1
- package/dist/cjs/pkce.js +6 -0
- package/dist/cjs/pkce.js.map +1 -1
- package/dist/cjs/server/eksWorkloadIdentity.d.ts +22 -0
- package/dist/cjs/server/eksWorkloadIdentity.d.ts.map +1 -0
- package/dist/cjs/server/eksWorkloadIdentity.js +117 -0
- package/dist/cjs/server/eksWorkloadIdentity.js.map +1 -0
- package/dist/cjs/server/index.d.ts +6 -0
- package/dist/cjs/server/index.d.ts.map +1 -1
- package/dist/cjs/server/index.js +8 -1
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/server/privateKey.d.ts +47 -0
- package/dist/cjs/server/privateKey.d.ts.map +1 -0
- package/dist/cjs/server/privateKey.js +233 -0
- package/dist/cjs/server/privateKey.js.map +1 -0
- package/dist/cjs/server/webIdentity.d.ts +37 -0
- package/dist/cjs/server/webIdentity.d.ts.map +1 -0
- package/dist/cjs/server/webIdentity.js +75 -0
- package/dist/cjs/server/webIdentity.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pkce.d.ts +4 -0
- package/dist/esm/pkce.d.ts.map +1 -1
- package/dist/esm/pkce.js +6 -0
- package/dist/esm/pkce.js.map +1 -1
- package/dist/esm/server/eksWorkloadIdentity.d.ts +22 -0
- package/dist/esm/server/eksWorkloadIdentity.d.ts.map +1 -0
- package/dist/esm/server/eksWorkloadIdentity.js +80 -0
- package/dist/esm/server/eksWorkloadIdentity.js.map +1 -0
- package/dist/esm/server/index.d.ts +6 -0
- package/dist/esm/server/index.d.ts.map +1 -1
- package/dist/esm/server/index.js +3 -0
- package/dist/esm/server/index.js.map +1 -1
- package/dist/esm/server/privateKey.d.ts +47 -0
- package/dist/esm/server/privateKey.d.ts.map +1 -0
- package/dist/esm/server/privateKey.js +195 -0
- package/dist/esm/server/privateKey.js.map +1 -0
- package/dist/esm/server/webIdentity.d.ts +37 -0
- package/dist/esm/server/webIdentity.d.ts.map +1 -0
- package/dist/esm/server/webIdentity.js +71 -0
- package/dist/esm/server/webIdentity.js.map +1 -0
- package/package.json +1 -1
package/dist/esm/server/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { AccessContext } from "./accessContext.js";
|
|
2
2
|
export { TokenVerifier } from "./tokenVerifier.js";
|
|
3
3
|
export { ClientSecret } from "./clientSecret.js";
|
|
4
|
+
export { FilePrivateKeyStorage, PrivateKeyManager } from "./privateKey.js";
|
|
5
|
+
export { WebIdentity } from "./webIdentity.js";
|
|
6
|
+
export { EKSWorkloadIdentity } from "./eksWorkloadIdentity.js";
|
|
4
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface JsonWebKey {
|
|
2
|
+
kty: string;
|
|
3
|
+
alg?: string;
|
|
4
|
+
use?: string;
|
|
5
|
+
kid?: string;
|
|
6
|
+
n?: string;
|
|
7
|
+
e?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface PrivateKeyStorage {
|
|
11
|
+
exists(keyId: string): Promise<boolean>;
|
|
12
|
+
storeKeyPair(keyId: string, privateKeyPem: string, publicKeyJwk: JsonWebKey): Promise<void>;
|
|
13
|
+
loadKeyPair(keyId: string): Promise<{
|
|
14
|
+
privateKeyPem: string;
|
|
15
|
+
publicKeyJwk: JsonWebKey;
|
|
16
|
+
}>;
|
|
17
|
+
deleteKeyPair(keyId: string): Promise<boolean>;
|
|
18
|
+
listKeyIds(): Promise<string[]>;
|
|
19
|
+
}
|
|
20
|
+
export declare class FilePrivateKeyStorage implements PrivateKeyStorage {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(storageDir: string);
|
|
23
|
+
exists(keyId: string): Promise<boolean>;
|
|
24
|
+
storeKeyPair(keyId: string, privateKeyPem: string, publicKeyJwk: JsonWebKey): Promise<void>;
|
|
25
|
+
loadKeyPair(keyId: string): Promise<{
|
|
26
|
+
privateKeyPem: string;
|
|
27
|
+
publicKeyJwk: JsonWebKey;
|
|
28
|
+
}>;
|
|
29
|
+
deleteKeyPair(keyId: string): Promise<boolean>;
|
|
30
|
+
listKeyIds(): Promise<string[]>;
|
|
31
|
+
}
|
|
32
|
+
export declare class PrivateKeyManager {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(options: {
|
|
35
|
+
storage: PrivateKeyStorage;
|
|
36
|
+
keyId?: string;
|
|
37
|
+
audienceConfig?: string | Record<string, string>;
|
|
38
|
+
});
|
|
39
|
+
bootstrapIdentity(): Promise<void>;
|
|
40
|
+
createClientAssertion(issuer: string, audience: string, expirySeconds?: number): Promise<string>;
|
|
41
|
+
getPublicJwks(): {
|
|
42
|
+
keys: JsonWebKey[];
|
|
43
|
+
};
|
|
44
|
+
getClientId(): string;
|
|
45
|
+
getClientJwksUrl(resourceServerUrl: string): string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=privateKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privateKey.d.ts","sourceRoot":"","sources":["../../../src/server/privateKey.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5F,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACzF,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACjC;AAMD,qBAAa,qBAAsB,YAAW,iBAAiB;;gBAGjD,UAAU,EAAE,MAAM;IAIxB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvC,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,IAAI,CAAC;IAeV,WAAW,CACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,UAAU,CAAA;KAAE,CAAC;IASzD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO9C,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAqBtC;AAMD,qBAAa,iBAAiB;;gBAOhB,OAAO,EAAE;QACnB,OAAO,EAAE,iBAAiB,CAAC;QAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClD;IAMK,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUlC,qBAAqB,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,aAAa,SAAM,GAClB,OAAO,CAAC,MAAM,CAAC;IAiBlB,aAAa,IAAI;QAAE,IAAI,EAAE,UAAU,EAAE,CAAA;KAAE;IAOvC,WAAW,IAAI,MAAM;IAIrB,gBAAgB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM;CA0BpD"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _FilePrivateKeyStorage_instances, _FilePrivateKeyStorage_storageDir, _FilePrivateKeyStorage_keyPath, _FilePrivateKeyStorage_metadataPath, _PrivateKeyManager_instances, _PrivateKeyManager_storage, _PrivateKeyManager_keyId, _PrivateKeyManager_audienceConfig, _PrivateKeyManager_privateKeyPem, _PrivateKeyManager_publicKeyJwk, _PrivateKeyManager_generateAndStoreKeyPair, _PemPrivateKeyring_pem, _PemPrivateKeyring_kid, _PemPrivateKeyring_issuer;
|
|
13
|
+
import * as crypto from "node:crypto";
|
|
14
|
+
import * as fs from "node:fs/promises";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import { JWTSigner } from "../jwt/signer.js";
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// File-Based Storage
|
|
19
|
+
// =============================================================================
|
|
20
|
+
export class FilePrivateKeyStorage {
|
|
21
|
+
constructor(storageDir) {
|
|
22
|
+
_FilePrivateKeyStorage_instances.add(this);
|
|
23
|
+
_FilePrivateKeyStorage_storageDir.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _FilePrivateKeyStorage_storageDir, storageDir, "f");
|
|
25
|
+
}
|
|
26
|
+
async exists(keyId) {
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_keyPath).call(this, keyId));
|
|
29
|
+
await fs.access(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_metadataPath).call(this, keyId));
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async storeKeyPair(keyId, privateKeyPem, publicKeyJwk) {
|
|
37
|
+
await fs.mkdir(__classPrivateFieldGet(this, _FilePrivateKeyStorage_storageDir, "f"), { recursive: true });
|
|
38
|
+
const metadata = {
|
|
39
|
+
key_id: keyId,
|
|
40
|
+
public_key_jwk: publicKeyJwk,
|
|
41
|
+
created_at: Date.now() / 1000,
|
|
42
|
+
algorithm: "RS256",
|
|
43
|
+
};
|
|
44
|
+
await fs.writeFile(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_keyPath).call(this, keyId), privateKeyPem, { encoding: "utf-8", mode: 0o600 });
|
|
45
|
+
await fs.writeFile(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_metadataPath).call(this, keyId), JSON.stringify(metadata, null, 2), {
|
|
46
|
+
encoding: "utf-8",
|
|
47
|
+
mode: 0o644,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async loadKeyPair(keyId) {
|
|
51
|
+
const [privateKeyPem, metadataRaw] = await Promise.all([
|
|
52
|
+
fs.readFile(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_keyPath).call(this, keyId), "utf-8"),
|
|
53
|
+
fs.readFile(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_metadataPath).call(this, keyId), "utf-8"),
|
|
54
|
+
]);
|
|
55
|
+
const metadata = JSON.parse(metadataRaw);
|
|
56
|
+
return { privateKeyPem, publicKeyJwk: metadata.public_key_jwk };
|
|
57
|
+
}
|
|
58
|
+
async deleteKeyPair(keyId) {
|
|
59
|
+
let deleted = false;
|
|
60
|
+
try {
|
|
61
|
+
await fs.unlink(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_keyPath).call(this, keyId));
|
|
62
|
+
deleted = true;
|
|
63
|
+
}
|
|
64
|
+
catch { /* ignore */ }
|
|
65
|
+
try {
|
|
66
|
+
await fs.unlink(__classPrivateFieldGet(this, _FilePrivateKeyStorage_instances, "m", _FilePrivateKeyStorage_metadataPath).call(this, keyId));
|
|
67
|
+
deleted = true;
|
|
68
|
+
}
|
|
69
|
+
catch { /* ignore */ }
|
|
70
|
+
return deleted;
|
|
71
|
+
}
|
|
72
|
+
async listKeyIds() {
|
|
73
|
+
try {
|
|
74
|
+
const files = await fs.readdir(__classPrivateFieldGet(this, _FilePrivateKeyStorage_storageDir, "f"));
|
|
75
|
+
const keyIds = [];
|
|
76
|
+
for (const file of files.filter((f) => f.endsWith(".json"))) {
|
|
77
|
+
const keyId = file.replace(/\.json$/, "");
|
|
78
|
+
if (await this.exists(keyId))
|
|
79
|
+
keyIds.push(keyId);
|
|
80
|
+
}
|
|
81
|
+
return keyIds.sort();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
_FilePrivateKeyStorage_storageDir = new WeakMap(), _FilePrivateKeyStorage_instances = new WeakSet(), _FilePrivateKeyStorage_keyPath = function _FilePrivateKeyStorage_keyPath(keyId) {
|
|
89
|
+
return path.join(__classPrivateFieldGet(this, _FilePrivateKeyStorage_storageDir, "f"), `${keyId}.pem`);
|
|
90
|
+
}, _FilePrivateKeyStorage_metadataPath = function _FilePrivateKeyStorage_metadataPath(keyId) {
|
|
91
|
+
return path.join(__classPrivateFieldGet(this, _FilePrivateKeyStorage_storageDir, "f"), `${keyId}.json`);
|
|
92
|
+
};
|
|
93
|
+
// =============================================================================
|
|
94
|
+
// Private Key Manager
|
|
95
|
+
// =============================================================================
|
|
96
|
+
export class PrivateKeyManager {
|
|
97
|
+
constructor(options) {
|
|
98
|
+
_PrivateKeyManager_instances.add(this);
|
|
99
|
+
_PrivateKeyManager_storage.set(this, void 0);
|
|
100
|
+
_PrivateKeyManager_keyId.set(this, void 0);
|
|
101
|
+
_PrivateKeyManager_audienceConfig.set(this, void 0);
|
|
102
|
+
_PrivateKeyManager_privateKeyPem.set(this, void 0);
|
|
103
|
+
_PrivateKeyManager_publicKeyJwk.set(this, void 0);
|
|
104
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_storage, options.storage, "f");
|
|
105
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_keyId, options.keyId ?? crypto.randomUUID(), "f");
|
|
106
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_audienceConfig, options.audienceConfig, "f");
|
|
107
|
+
}
|
|
108
|
+
async bootstrapIdentity() {
|
|
109
|
+
if (await __classPrivateFieldGet(this, _PrivateKeyManager_storage, "f").exists(__classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f"))) {
|
|
110
|
+
const { privateKeyPem, publicKeyJwk } = await __classPrivateFieldGet(this, _PrivateKeyManager_storage, "f").loadKeyPair(__classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f"));
|
|
111
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_privateKeyPem, privateKeyPem, "f");
|
|
112
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_publicKeyJwk, publicKeyJwk, "f");
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
await __classPrivateFieldGet(this, _PrivateKeyManager_instances, "m", _PrivateKeyManager_generateAndStoreKeyPair).call(this);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async createClientAssertion(issuer, audience, expirySeconds = 300) {
|
|
119
|
+
if (!__classPrivateFieldGet(this, _PrivateKeyManager_privateKeyPem, "f") || !__classPrivateFieldGet(this, _PrivateKeyManager_publicKeyJwk, "f")) {
|
|
120
|
+
throw new Error("Identity not bootstrapped. Call bootstrapIdentity() first.");
|
|
121
|
+
}
|
|
122
|
+
const keyring = new PemPrivateKeyring(__classPrivateFieldGet(this, _PrivateKeyManager_privateKeyPem, "f"), __classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f"), issuer);
|
|
123
|
+
const signer = new JWTSigner(keyring);
|
|
124
|
+
const now = Math.floor(Date.now() / 1000);
|
|
125
|
+
return signer.sign({
|
|
126
|
+
iss: issuer,
|
|
127
|
+
sub: issuer,
|
|
128
|
+
aud: audience,
|
|
129
|
+
jti: crypto.randomUUID(),
|
|
130
|
+
iat: now,
|
|
131
|
+
exp: now + expirySeconds,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
getPublicJwks() {
|
|
135
|
+
if (!__classPrivateFieldGet(this, _PrivateKeyManager_publicKeyJwk, "f")) {
|
|
136
|
+
throw new Error("Identity not bootstrapped. Call bootstrapIdentity() first.");
|
|
137
|
+
}
|
|
138
|
+
return { keys: [__classPrivateFieldGet(this, _PrivateKeyManager_publicKeyJwk, "f")] };
|
|
139
|
+
}
|
|
140
|
+
getClientId() {
|
|
141
|
+
return __classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f");
|
|
142
|
+
}
|
|
143
|
+
getClientJwksUrl(resourceServerUrl) {
|
|
144
|
+
const url = new URL(resourceServerUrl);
|
|
145
|
+
return `${url.protocol}//${url.host}/.well-known/jwks.json`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
_PrivateKeyManager_storage = new WeakMap(), _PrivateKeyManager_keyId = new WeakMap(), _PrivateKeyManager_audienceConfig = new WeakMap(), _PrivateKeyManager_privateKeyPem = new WeakMap(), _PrivateKeyManager_publicKeyJwk = new WeakMap(), _PrivateKeyManager_instances = new WeakSet(), _PrivateKeyManager_generateAndStoreKeyPair = async function _PrivateKeyManager_generateAndStoreKeyPair() {
|
|
149
|
+
const keyPair = crypto.generateKeyPairSync("rsa", {
|
|
150
|
+
modulusLength: 2048,
|
|
151
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
152
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
153
|
+
});
|
|
154
|
+
const privateKeyPem = String(keyPair.privateKey);
|
|
155
|
+
const publicKeyObj = crypto.createPublicKey(String(keyPair.publicKey));
|
|
156
|
+
const jwk = publicKeyObj.export({ format: "jwk" });
|
|
157
|
+
const publicKeyJwk = {
|
|
158
|
+
kty: jwk.kty,
|
|
159
|
+
n: jwk.n,
|
|
160
|
+
e: jwk.e,
|
|
161
|
+
kid: __classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f"),
|
|
162
|
+
alg: "RS256",
|
|
163
|
+
use: "sig",
|
|
164
|
+
};
|
|
165
|
+
await __classPrivateFieldGet(this, _PrivateKeyManager_storage, "f").storeKeyPair(__classPrivateFieldGet(this, _PrivateKeyManager_keyId, "f"), privateKeyPem, publicKeyJwk);
|
|
166
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_privateKeyPem, privateKeyPem, "f");
|
|
167
|
+
__classPrivateFieldSet(this, _PrivateKeyManager_publicKeyJwk, publicKeyJwk, "f");
|
|
168
|
+
};
|
|
169
|
+
// =============================================================================
|
|
170
|
+
// PEM-based PrivateKeyring adapter (implements PrivateKeyring from @keycardai/oauth)
|
|
171
|
+
// =============================================================================
|
|
172
|
+
class PemPrivateKeyring {
|
|
173
|
+
constructor(pem, kid, issuer) {
|
|
174
|
+
_PemPrivateKeyring_pem.set(this, void 0);
|
|
175
|
+
_PemPrivateKeyring_kid.set(this, void 0);
|
|
176
|
+
_PemPrivateKeyring_issuer.set(this, void 0);
|
|
177
|
+
__classPrivateFieldSet(this, _PemPrivateKeyring_pem, pem, "f");
|
|
178
|
+
__classPrivateFieldSet(this, _PemPrivateKeyring_kid, kid, "f");
|
|
179
|
+
__classPrivateFieldSet(this, _PemPrivateKeyring_issuer, issuer, "f");
|
|
180
|
+
}
|
|
181
|
+
async key(_usage) {
|
|
182
|
+
const keyObj = crypto.createPrivateKey(__classPrivateFieldGet(this, _PemPrivateKeyring_pem, "f"));
|
|
183
|
+
const jwk = keyObj.export({ format: "jwk" });
|
|
184
|
+
const cryptoKey = await crypto.subtle.importKey("jwk", jwk, { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } }, false, ["sign"]);
|
|
185
|
+
return {
|
|
186
|
+
// node:crypto.webcrypto.CryptoKey and global CryptoKey are identical at
|
|
187
|
+
// runtime; the declaration split is a TypeScript-only artefact.
|
|
188
|
+
key: cryptoKey,
|
|
189
|
+
kid: __classPrivateFieldGet(this, _PemPrivateKeyring_kid, "f"),
|
|
190
|
+
issuer: __classPrivateFieldGet(this, _PemPrivateKeyring_issuer, "f"),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
_PemPrivateKeyring_pem = new WeakMap(), _PemPrivateKeyring_kid = new WeakMap(), _PemPrivateKeyring_issuer = new WeakMap();
|
|
195
|
+
//# sourceMappingURL=privateKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privateKey.js","sourceRoot":"","sources":["../../../src/server/privateKey.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAuB7C,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,MAAM,OAAO,qBAAqB;IAGhC,YAAY,UAAkB;;QAF9B,oDAAoB;QAGlB,uBAAA,IAAI,qCAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa;QACxB,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,uBAAA,IAAI,wEAAS,MAAb,IAAI,EAAU,KAAK,CAAC,CAAC,CAAC;YACtC,MAAM,EAAE,CAAC,MAAM,CAAC,uBAAA,IAAI,6EAAc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M,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC7C,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EACxD,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;QACF,OAAO;YACL,wEAAwE;YACxE,gEAAgE;YAChE,GAAG,EAAE,SAAsB;YAC3B,GAAG,EAAE,uBAAA,IAAI,8BAAK;YACd,MAAM,EAAE,uBAAA,IAAI,iCAAQ;SACrB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ApplicationCredential } from "../credentials.js";
|
|
2
|
+
import type { TokenExchangeRequest } from "../tokenExchange.js";
|
|
3
|
+
import type { PrivateKeyStorage } from "./privateKey.js";
|
|
4
|
+
export type { PrivateKeyStorage } from "./privateKey.js";
|
|
5
|
+
export interface WebIdentityOptions {
|
|
6
|
+
serverName?: string;
|
|
7
|
+
storage?: PrivateKeyStorage;
|
|
8
|
+
storageDir?: string;
|
|
9
|
+
keyId?: string;
|
|
10
|
+
audienceConfig?: string | Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* RFC 7523 private_key_jwt client assertion credential provider.
|
|
14
|
+
*
|
|
15
|
+
* Generates and persists an RSA key pair using the supplied storage
|
|
16
|
+
* implementation (default: `FilePrivateKeyStorage("./mcp_keys")`).
|
|
17
|
+
* On each token exchange the private key signs a client assertion JWT
|
|
18
|
+
* that the authorization server verifies instead of a shared secret.
|
|
19
|
+
*
|
|
20
|
+
* **Requires Node.js.** Key generation and storage use Node.js crypto
|
|
21
|
+
* and filesystem APIs.
|
|
22
|
+
*/
|
|
23
|
+
export declare class WebIdentity implements ApplicationCredential {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(options?: WebIdentityOptions);
|
|
26
|
+
bootstrap(): Promise<void>;
|
|
27
|
+
getAuth(): null;
|
|
28
|
+
prepareTokenExchangeRequest(subjectToken: string, resource: string, options?: {
|
|
29
|
+
tokenEndpoint?: string;
|
|
30
|
+
authInfo?: Record<string, string>;
|
|
31
|
+
}): Promise<TokenExchangeRequest>;
|
|
32
|
+
getPublicJwks(): {
|
|
33
|
+
keys: Record<string, unknown>[];
|
|
34
|
+
};
|
|
35
|
+
getClientJwksUrl(resourceServerUrl: string): string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=webIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webIdentity.d.ts","sourceRoot":"","sources":["../../../src/server/webIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD;AAED;;;;;;;;;;GAUG;AACH,qBAAa,WAAY,YAAW,qBAAqB;;gBAI3C,OAAO,GAAE,kBAAuB;IAiBtC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAOhC,OAAO,IAAI,IAAI;IAIT,2BAA2B,CAC/B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GACtE,OAAO,CAAC,oBAAoB,CAAC;IAchC,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE;IAIpD,gBAAgB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM;CAGpD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _WebIdentity_keyManager, _WebIdentity_bootstrapPromise;
|
|
13
|
+
import { PrivateKeyManager, FilePrivateKeyStorage } from "./privateKey.js";
|
|
14
|
+
/**
|
|
15
|
+
* RFC 7523 private_key_jwt client assertion credential provider.
|
|
16
|
+
*
|
|
17
|
+
* Generates and persists an RSA key pair using the supplied storage
|
|
18
|
+
* implementation (default: `FilePrivateKeyStorage("./mcp_keys")`).
|
|
19
|
+
* On each token exchange the private key signs a client assertion JWT
|
|
20
|
+
* that the authorization server verifies instead of a shared secret.
|
|
21
|
+
*
|
|
22
|
+
* **Requires Node.js.** Key generation and storage use Node.js crypto
|
|
23
|
+
* and filesystem APIs.
|
|
24
|
+
*/
|
|
25
|
+
export class WebIdentity {
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
_WebIdentity_keyManager.set(this, void 0);
|
|
28
|
+
_WebIdentity_bootstrapPromise.set(this, void 0);
|
|
29
|
+
const storage = options.storage ??
|
|
30
|
+
new FilePrivateKeyStorage(options.storageDir ?? "./mcp_keys");
|
|
31
|
+
let keyId = options.keyId;
|
|
32
|
+
if (!keyId && options.serverName) {
|
|
33
|
+
keyId = options.serverName.replace(/[^a-zA-Z0-9\-_]/g, "_");
|
|
34
|
+
}
|
|
35
|
+
__classPrivateFieldSet(this, _WebIdentity_keyManager, new PrivateKeyManager({
|
|
36
|
+
storage,
|
|
37
|
+
keyId,
|
|
38
|
+
audienceConfig: options.audienceConfig,
|
|
39
|
+
}), "f");
|
|
40
|
+
}
|
|
41
|
+
async bootstrap() {
|
|
42
|
+
if (!__classPrivateFieldGet(this, _WebIdentity_bootstrapPromise, "f")) {
|
|
43
|
+
__classPrivateFieldSet(this, _WebIdentity_bootstrapPromise, __classPrivateFieldGet(this, _WebIdentity_keyManager, "f").bootstrapIdentity(), "f");
|
|
44
|
+
}
|
|
45
|
+
return __classPrivateFieldGet(this, _WebIdentity_bootstrapPromise, "f");
|
|
46
|
+
}
|
|
47
|
+
getAuth() {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
async prepareTokenExchangeRequest(subjectToken, resource, options) {
|
|
51
|
+
await this.bootstrap();
|
|
52
|
+
const issuer = options?.authInfo?.resource_client_id ?? __classPrivateFieldGet(this, _WebIdentity_keyManager, "f").getClientId();
|
|
53
|
+
const audience = options?.tokenEndpoint ?? issuer;
|
|
54
|
+
const clientAssertion = await __classPrivateFieldGet(this, _WebIdentity_keyManager, "f").createClientAssertion(issuer, audience);
|
|
55
|
+
return {
|
|
56
|
+
subjectToken,
|
|
57
|
+
resource,
|
|
58
|
+
subjectTokenType: "urn:ietf:params:oauth:token-type:access_token",
|
|
59
|
+
clientAssertionType: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
|
60
|
+
clientAssertion,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
getPublicJwks() {
|
|
64
|
+
return __classPrivateFieldGet(this, _WebIdentity_keyManager, "f").getPublicJwks();
|
|
65
|
+
}
|
|
66
|
+
getClientJwksUrl(resourceServerUrl) {
|
|
67
|
+
return __classPrivateFieldGet(this, _WebIdentity_keyManager, "f").getClientJwksUrl(resourceServerUrl);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
_WebIdentity_keyManager = new WeakMap(), _WebIdentity_bootstrapPromise = new WeakMap();
|
|
71
|
+
//# sourceMappingURL=webIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webIdentity.js","sourceRoot":"","sources":["../../../src/server/webIdentity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAa3E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAW;IAItB,YAAY,UAA8B,EAAE;QAH5C,0CAA+B;QAC/B,gDAAkC;QAGhC,MAAM,OAAO,GACX,OAAO,CAAC,OAAO;YACf,IAAI,qBAAqB,CAAC,OAAO,CAAC,UAAU,IAAI,YAAY,CAAC,CAAC;QAEhE,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACjC,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;QAED,uBAAA,IAAI,2BAAe,IAAI,iBAAiB,CAAC;YACvC,OAAO;YACP,KAAK;YACL,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,MAAA,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,uBAAA,IAAI,qCAAkB,EAAE,CAAC;YAC5B,uBAAA,IAAI,iCAAqB,uBAAA,IAAI,+BAAY,CAAC,iBAAiB,EAAE,MAAA,CAAC;QAChE,CAAC;QACD,OAAO,uBAAA,IAAI,qCAAkB,CAAC;IAChC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,2BAA2B,CAC/B,YAAoB,EACpB,QAAgB,EAChB,OAAuE;QAEvE,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,OAAO,EAAE,QAAQ,EAAE,kBAAkB,IAAI,uBAAA,IAAI,+BAAY,CAAC,WAAW,EAAE,CAAC;QACvF,MAAM,QAAQ,GAAG,OAAO,EAAE,aAAa,IAAI,MAAM,CAAC;QAClD,MAAM,eAAe,GAAG,MAAM,uBAAA,IAAI,+BAAY,CAAC,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACvF,OAAO;YACL,YAAY;YACZ,QAAQ;YACR,gBAAgB,EAAE,+CAA+C;YACjE,mBAAmB,EAAE,wDAAwD;YAC7E,eAAe;SAChB,CAAC;IACJ,CAAC;IAED,aAAa;QACX,OAAO,uBAAA,IAAI,+BAAY,CAAC,aAAa,EAAE,CAAC;IAC1C,CAAC;IAED,gBAAgB,CAAC,iBAAyB;QACxC,OAAO,uBAAA,IAAI,+BAAY,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keycardai/oauth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "[Preview] OAuth 2.0 primitives for Keycard: JWKS keyring, JWT signing/verification, server-tier token verifier, AccessContext, ClientSecret credentials, and impersonation via RFC 8693 token exchange",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|