@hawcx/oauth-client 0.2.0 → 4.0.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 +475 -210
- package/dist/delegation/credentials.d.ts +92 -0
- package/dist/delegation/credentials.d.ts.map +1 -0
- package/dist/delegation/credentials.js +215 -0
- package/dist/delegation/credentials.js.map +1 -0
- package/dist/delegation/crypto.d.ts +2 -2
- package/dist/delegation/crypto.d.ts.map +1 -1
- package/dist/delegation/crypto.js +41 -32
- package/dist/delegation/crypto.js.map +1 -1
- package/dist/delegation/exceptions.d.ts +12 -5
- package/dist/delegation/exceptions.d.ts.map +1 -1
- package/dist/delegation/exceptions.js +12 -14
- package/dist/delegation/exceptions.js.map +1 -1
- package/dist/delegation/factory.d.ts +20 -0
- package/dist/delegation/factory.d.ts.map +1 -0
- package/dist/delegation/factory.js +49 -0
- package/dist/delegation/factory.js.map +1 -0
- package/dist/delegation/hawcx.d.ts +67 -224
- package/dist/delegation/hawcx.d.ts.map +1 -1
- package/dist/delegation/hawcx.js +116 -299
- package/dist/delegation/hawcx.js.map +1 -1
- package/dist/delegation/index.d.ts +4 -9
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js +5 -17
- package/dist/delegation/index.js.map +1 -1
- package/dist/delegation/transport.d.ts +40 -0
- package/dist/delegation/transport.d.ts.map +1 -0
- package/dist/delegation/transport.js +120 -0
- package/dist/delegation/transport.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -27
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +98 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +150 -0
- package/dist/oauth.js.map +1 -0
- package/dist/stepup/client.d.ts +26 -0
- package/dist/stepup/client.d.ts.map +1 -0
- package/dist/stepup/client.js +84 -0
- package/dist/stepup/client.js.map +1 -0
- package/dist/stepup/index.d.ts +3 -0
- package/dist/stepup/index.d.ts.map +1 -0
- package/dist/stepup/index.js +19 -0
- package/dist/stepup/index.js.map +1 -0
- package/dist/stepup/types.d.ts +36 -0
- package/dist/stepup/types.d.ts.map +1 -0
- package/dist/stepup/types.js +3 -0
- package/dist/stepup/types.js.map +1 -0
- package/package.json +16 -17
- package/LICENSE +0 -22
- package/dist/client.d.ts +0 -134
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -300
- package/dist/client.js.map +0 -1
- package/dist/delegation/client.d.ts +0 -116
- package/dist/delegation/client.d.ts.map +0 -1
- package/dist/delegation/client.js +0 -227
- package/dist/delegation/client.js.map +0 -1
- package/dist/exceptions.d.ts +0 -52
- package/dist/exceptions.d.ts.map +0 -1
- package/dist/exceptions.js +0 -81
- package/dist/exceptions.js.map +0 -1
- package/dist/utils.d.ts +0 -61
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -263
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StepUpClient = void 0;
|
|
4
|
+
const factory_1 = require("../delegation/factory");
|
|
5
|
+
const exceptions_1 = require("../delegation/exceptions");
|
|
6
|
+
class StepUpClient {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.transport = options.transport;
|
|
9
|
+
this.options = options.clientOptions;
|
|
10
|
+
this.apiKey = options.apiKey;
|
|
11
|
+
}
|
|
12
|
+
static fromSecretKey(options) {
|
|
13
|
+
const { apiKey } = options;
|
|
14
|
+
const transport = (0, factory_1.buildTransportFromSecretKey)(options);
|
|
15
|
+
return new StepUpClient({ transport, clientOptions: options, apiKey });
|
|
16
|
+
}
|
|
17
|
+
static fromKeys(options) {
|
|
18
|
+
const { apiKey } = options;
|
|
19
|
+
const transport = (0, factory_1.buildTransportFromKeys)(options);
|
|
20
|
+
return new StepUpClient({ transport, clientOptions: options, apiKey });
|
|
21
|
+
}
|
|
22
|
+
buildExtraHeaders() {
|
|
23
|
+
const headers = {
|
|
24
|
+
'X-Hawcx-Protocol-Version': '1',
|
|
25
|
+
...(this.options.extraHeaders || {}),
|
|
26
|
+
};
|
|
27
|
+
if (this.apiKey) {
|
|
28
|
+
headers['apikey'] = this.apiKey;
|
|
29
|
+
}
|
|
30
|
+
if (this.options.relyingParty) {
|
|
31
|
+
headers['X-Relying-Party'] = this.options.relyingParty;
|
|
32
|
+
}
|
|
33
|
+
if (this.options.tenantHeaderName && this.options.tenantHeaderValue) {
|
|
34
|
+
headers[this.options.tenantHeaderName] = this.options.tenantHeaderValue;
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
async startToken(options) {
|
|
39
|
+
try {
|
|
40
|
+
const apiPrefix = this.options.apiPrefix ?? '/v1';
|
|
41
|
+
const payload = {
|
|
42
|
+
subject_userid: options.userId,
|
|
43
|
+
purpose: options.purpose,
|
|
44
|
+
};
|
|
45
|
+
if (options.newMfaMethod) {
|
|
46
|
+
payload.new_mfa_method = options.newMfaMethod;
|
|
47
|
+
}
|
|
48
|
+
if (options.newPhoneNumber) {
|
|
49
|
+
payload.new_phone_number = options.newPhoneNumber;
|
|
50
|
+
}
|
|
51
|
+
return (await this.transport.send({
|
|
52
|
+
endpoint: `${apiPrefix}/management/stepup/start-token`,
|
|
53
|
+
payload,
|
|
54
|
+
headers: this.buildExtraHeaders(),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof exceptions_1.DelegationError) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
throw new exceptions_1.DelegationRequestError('stepup.start-token failed', { cause: error });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async consumeReceipt(options) {
|
|
65
|
+
try {
|
|
66
|
+
const apiPrefix = this.options.apiPrefix ?? '/v1';
|
|
67
|
+
return (await this.transport.send({
|
|
68
|
+
endpoint: `${apiPrefix}/management/stepup/consume`,
|
|
69
|
+
payload: {
|
|
70
|
+
step_up_receipt: options.receipt,
|
|
71
|
+
},
|
|
72
|
+
headers: this.buildExtraHeaders(),
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof exceptions_1.DelegationError) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
throw new exceptions_1.DelegationRequestError('stepup.consume failed', { cause: error });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.StepUpClient = StepUpClient;
|
|
84
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/stepup/client.ts"],"names":[],"mappings":";;;AACA,mDAAmH;AACnH,yDAAmF;AAgBnF,MAAa,YAAY;IAKvB,YAAY,OAIX;QACC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,OAAqC;QACxD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAA,qCAA2B,EAAC,OAAO,CAAC,CAAC;QACvD,OAAO,IAAI,YAAY,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAA+B;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAA,gCAAsB,EAAC,OAAO,CAAC,CAAC;QAClD,OAAO,I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C,SAAS,CAAC,IAAI,CAG/B;gBACA,QAAQ,EAAE,GAAG,SAAS,gCAAgC;gBACtD,OAAO;gBACP,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE;aAClC,CAAC,CAA6B,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,4BAAe,EAAE,CAAC;gBACrC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,mCAAsB,CAAC,2BAA2B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA6B;QAChD,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;YAClD,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAG/B;gBACA,QAAQ,EAAE,GAAG,SAAS,4BAA4B;gBAClD,OAAO,EAAE;oBACP,eAAe,EAAE,OAAO,CAAC,OAAO;iBACjC;gBACD,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE;aAClC,CAAC,CAA0B,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,4BAAe,EAAE,CAAC;gBACrC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,mCAAsB,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;CACF;AA/FD,oCA+FC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stepup/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stepup/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type StepUpPurpose = 'change_mfa_method' | 'change_phone_number';
|
|
2
|
+
export type HxAuthMfaMethod = 'sms_otp' | 'email_otp' | 'totp';
|
|
3
|
+
export interface StepUpStartTokenResponse {
|
|
4
|
+
start_token: string;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
}
|
|
7
|
+
export interface StepUpConsumeResponse {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface StepUpStartOptions {
|
|
11
|
+
userId: string;
|
|
12
|
+
purpose: StepUpPurpose;
|
|
13
|
+
newMfaMethod?: HxAuthMfaMethod;
|
|
14
|
+
newPhoneNumber?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface StepUpConsumeOptions {
|
|
17
|
+
receipt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface StepUpClientBaseOptions {
|
|
20
|
+
/** Base URL to hx_auth, e.g. http://localhost:8000 */
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
/** API version prefix (default: /v1) */
|
|
23
|
+
apiPrefix?: string;
|
|
24
|
+
/** Required by hx_auth for tenant routing in most deployments (forwarded via headers). */
|
|
25
|
+
tenantHeaderName?: string;
|
|
26
|
+
tenantHeaderValue?: string;
|
|
27
|
+
/** Required by hx_auth relying party validation. */
|
|
28
|
+
relyingParty?: string;
|
|
29
|
+
/** Optional additional headers (e.g., apikey) */
|
|
30
|
+
extraHeaders?: Record<string, string>;
|
|
31
|
+
/** Request timeout in seconds (default: 15) */
|
|
32
|
+
timeoutSeconds?: number;
|
|
33
|
+
/** Allowed response timestamp skew in seconds (default: 300) */
|
|
34
|
+
clockSkewSeconds?: number;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stepup/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAExE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAE/D,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,OAAO,CAAC;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stepup/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hawcx/oauth-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Simple OAuth client for Hawcx authentication with delegation support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"test": "jest",
|
|
10
|
-
"test:coverage": "jest --coverage",
|
|
11
10
|
"lint": "eslint 'src/**/*.ts'",
|
|
12
11
|
"format": "prettier --write 'src/**/*.ts'",
|
|
13
12
|
"prepublishOnly": "npm run build"
|
|
@@ -16,25 +15,27 @@
|
|
|
16
15
|
"oauth",
|
|
17
16
|
"jwt",
|
|
18
17
|
"authentication",
|
|
19
|
-
"oauth2",
|
|
20
|
-
"verification",
|
|
21
18
|
"hawcx",
|
|
19
|
+
"pkce",
|
|
22
20
|
"mfa",
|
|
23
|
-
"delegation"
|
|
24
|
-
"pkce"
|
|
21
|
+
"delegation"
|
|
25
22
|
],
|
|
26
23
|
"author": "Hawcx Team",
|
|
27
|
-
"license": "
|
|
24
|
+
"license": "UNLICENSED",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/hawcx/hawcx_node_oauth_client.git"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"registry": "https://registry.npmjs.org",
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
28
33
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"axios": "^1.6.0",
|
|
31
|
-
"uuid": "^9.0.0"
|
|
34
|
+
"jose": "^5.10.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@types/jest": "^29.5.0",
|
|
35
|
-
"@types/jsonwebtoken": "^9.0.5",
|
|
36
38
|
"@types/node": "^20.10.0",
|
|
37
|
-
"@types/uuid": "^9.0.0",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
39
40
|
"@typescript-eslint/parser": "^6.0.0",
|
|
40
41
|
"eslint": "^8.50.0",
|
|
@@ -44,12 +45,10 @@
|
|
|
44
45
|
"typescript": "^5.3.0"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
48
|
+
"node": ">=18.0.0"
|
|
48
49
|
},
|
|
49
50
|
"files": [
|
|
50
51
|
"dist",
|
|
51
|
-
"README.md"
|
|
52
|
-
"LICENSE"
|
|
52
|
+
"README.md"
|
|
53
53
|
]
|
|
54
54
|
}
|
|
55
|
-
|
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Hawcx
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
package/dist/client.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core OAuth client implementation
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Options for exchanging authorization code for claims
|
|
6
|
-
*/
|
|
7
|
-
export interface ExchangeCodeOptions {
|
|
8
|
-
/** Authorization code from OAuth flow */
|
|
9
|
-
code: string;
|
|
10
|
-
/** Token endpoint URL */
|
|
11
|
-
oauthTokenUrl: string;
|
|
12
|
-
/** OAuth client identifier */
|
|
13
|
-
clientId: string;
|
|
14
|
-
/** Ed25519 public key (PEM string or file path) - optional if jwksUrl provided */
|
|
15
|
-
publicKey?: string;
|
|
16
|
-
/** JWKS URL for dynamic key fetching (alternative to publicKey) */
|
|
17
|
-
jwksUrl?: string;
|
|
18
|
-
/** API key for OAuth provider (required for Hawcx) */
|
|
19
|
-
apiKey: string;
|
|
20
|
-
/** PKCE code verifier (optional, recommended for security) */
|
|
21
|
-
codeVerifier?: string;
|
|
22
|
-
/** OAuth redirect URI (optional, required by some providers) */
|
|
23
|
-
redirectUri?: string;
|
|
24
|
-
/** Request timeout in seconds (default: 20) */
|
|
25
|
-
timeout?: number;
|
|
26
|
-
/** Expected 'aud' claim (optional but recommended) */
|
|
27
|
-
audience?: string;
|
|
28
|
-
/** Expected 'iss' claim (optional but recommended) */
|
|
29
|
-
issuer?: string;
|
|
30
|
-
/** Verify token expiration (default: true) */
|
|
31
|
-
verifyExp?: boolean;
|
|
32
|
-
/** Clock skew tolerance in seconds (default: 0) */
|
|
33
|
-
leeway?: number;
|
|
34
|
-
/** List of allowed signing algorithms (default: RS256, ES256/384/512, EdDSA) */
|
|
35
|
-
algorithms?: string[];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Options for verifying JWT tokens
|
|
39
|
-
*/
|
|
40
|
-
export interface VerifyJwtOptions {
|
|
41
|
-
/** JWT token to verify */
|
|
42
|
-
token: string;
|
|
43
|
-
/** Public key for JWT verification (PEM string or file path) - optional if jwksUrl provided */
|
|
44
|
-
publicKey?: string;
|
|
45
|
-
/** JWKS URL for dynamic key fetching (alternative to publicKey) */
|
|
46
|
-
jwksUrl?: string;
|
|
47
|
-
/** Expected 'aud' claim (optional but recommended) */
|
|
48
|
-
audience?: string;
|
|
49
|
-
/** Expected 'iss' claim (optional but recommended) */
|
|
50
|
-
issuer?: string;
|
|
51
|
-
/** Verify token expiration (default: true) */
|
|
52
|
-
verifyExp?: boolean;
|
|
53
|
-
/** Clock skew tolerance in seconds (default: 0) */
|
|
54
|
-
leeway?: number;
|
|
55
|
-
/** List of allowed signing algorithms (default: RS256, ES256/384/512, EdDSA) */
|
|
56
|
-
algorithms?: string[];
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Exchange OAuth authorization code for verified JWT claims.
|
|
60
|
-
*
|
|
61
|
-
* Supports PKCE (Proof Key for Code Exchange) per RFC 7636 for enhanced security.
|
|
62
|
-
*
|
|
63
|
-
* @param options - Configuration options for code exchange
|
|
64
|
-
* @returns Dictionary containing the verified JWT claims
|
|
65
|
-
* @throws OAuthExchangeError - Code exchange failed
|
|
66
|
-
* @throws JWTVerificationError - JWT verification failed
|
|
67
|
-
* @throws InvalidPublicKeyError - Public key invalid
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // Basic usage
|
|
72
|
-
* const claims = await exchangeCodeForClaims({
|
|
73
|
-
* code: req.body.code,
|
|
74
|
-
* oauthTokenUrl: 'https://oauth.example.com/token',
|
|
75
|
-
* clientId: 'my-app',
|
|
76
|
-
* publicKey: '/path/to/public.pem'
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* // With PKCE (recommended)
|
|
80
|
-
* const claims = await exchangeCodeForClaims({
|
|
81
|
-
* code: req.body.code,
|
|
82
|
-
* oauthTokenUrl: 'https://oauth.example.com/token',
|
|
83
|
-
* clientId: 'my-app',
|
|
84
|
-
* publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
85
|
-
* codeVerifier: session.pkceVerifier,
|
|
86
|
-
* redirectUri: 'https://myapp.com/callback',
|
|
87
|
-
* audience: 'my-app',
|
|
88
|
-
* issuer: 'https://oauth.example.com'
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export declare function exchangeCodeForClaims(options: ExchangeCodeOptions): Promise<Record<string, any>>;
|
|
93
|
-
/**
|
|
94
|
-
* Exchange OAuth authorization code for verified JWT claims and the raw id_token.
|
|
95
|
-
*
|
|
96
|
-
* @param options - Configuration options for code exchange
|
|
97
|
-
* @returns Tuple containing [claims, idToken]
|
|
98
|
-
* @throws OAuthExchangeError - Code exchange failed
|
|
99
|
-
* @throws JWTVerificationError - JWT verification failed
|
|
100
|
-
* @throws InvalidPublicKeyError - Public key invalid
|
|
101
|
-
*/
|
|
102
|
-
export declare function exchangeCodeForTokenAndClaims(options: ExchangeCodeOptions): Promise<[Record<string, any>, string]>;
|
|
103
|
-
/**
|
|
104
|
-
* Verify a JWT and return its claims.
|
|
105
|
-
*
|
|
106
|
-
* This function verifies the JWT signature using the provided public key
|
|
107
|
-
* and validates claims (audience, issuer, expiration).
|
|
108
|
-
*
|
|
109
|
-
* @param options - Configuration options for JWT verification
|
|
110
|
-
* @returns Dictionary containing the verified JWT claims
|
|
111
|
-
* @throws JWTVerificationError - JWT verification failed
|
|
112
|
-
* @throws InvalidPublicKeyError - Public key invalid
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* // Basic usage
|
|
117
|
-
* const claims = verifyJwt({
|
|
118
|
-
* token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...',
|
|
119
|
-
* publicKey: 'keys/public.pem'
|
|
120
|
-
* });
|
|
121
|
-
* console.log(`User: ${claims.sub}`);
|
|
122
|
-
*
|
|
123
|
-
* // With validation
|
|
124
|
-
* const claims = verifyJwt({
|
|
125
|
-
* token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...',
|
|
126
|
-
* publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
127
|
-
* audience: 'my-app',
|
|
128
|
-
* issuer: 'https://oauth.example.com',
|
|
129
|
-
* leeway: 10 // Allow 10 seconds clock skew
|
|
130
|
-
* });
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export declare function verifyJwt(options: VerifyJwtOptions): Promise<Record<string, any>>;
|
|
134
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,IAAI,EAAE,MAA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