@hawcx/oauth-client 0.2.0 → 5.1.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.
Files changed (74) hide show
  1. package/README.md +587 -204
  2. package/dist/client-assertion.d.ts +45 -0
  3. package/dist/client-assertion.d.ts.map +1 -0
  4. package/dist/client-assertion.js +141 -0
  5. package/dist/client-assertion.js.map +1 -0
  6. package/dist/delegation/credentials.d.ts +92 -0
  7. package/dist/delegation/credentials.d.ts.map +1 -0
  8. package/dist/delegation/credentials.js +215 -0
  9. package/dist/delegation/credentials.js.map +1 -0
  10. package/dist/delegation/crypto.d.ts +2 -2
  11. package/dist/delegation/crypto.d.ts.map +1 -1
  12. package/dist/delegation/crypto.js +41 -32
  13. package/dist/delegation/crypto.js.map +1 -1
  14. package/dist/delegation/exceptions.d.ts +12 -5
  15. package/dist/delegation/exceptions.d.ts.map +1 -1
  16. package/dist/delegation/exceptions.js +12 -14
  17. package/dist/delegation/exceptions.js.map +1 -1
  18. package/dist/delegation/factory.d.ts +20 -0
  19. package/dist/delegation/factory.d.ts.map +1 -0
  20. package/dist/delegation/factory.js +49 -0
  21. package/dist/delegation/factory.js.map +1 -0
  22. package/dist/delegation/hawcx.d.ts +59 -224
  23. package/dist/delegation/hawcx.d.ts.map +1 -1
  24. package/dist/delegation/hawcx.js +99 -299
  25. package/dist/delegation/hawcx.js.map +1 -1
  26. package/dist/delegation/index.d.ts +4 -9
  27. package/dist/delegation/index.d.ts.map +1 -1
  28. package/dist/delegation/index.js +5 -17
  29. package/dist/delegation/index.js.map +1 -1
  30. package/dist/delegation/transport.d.ts +40 -0
  31. package/dist/delegation/transport.d.ts.map +1 -0
  32. package/dist/delegation/transport.js +120 -0
  33. package/dist/delegation/transport.js.map +1 -0
  34. package/dist/errors.d.ts +62 -0
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/errors.js +73 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/index.d.ts +12 -15
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +20 -27
  41. package/dist/index.js.map +1 -1
  42. package/dist/oauth.d.ts +265 -0
  43. package/dist/oauth.d.ts.map +1 -0
  44. package/dist/oauth.js +497 -0
  45. package/dist/oauth.js.map +1 -0
  46. package/dist/stepup/client.d.ts +26 -0
  47. package/dist/stepup/client.d.ts.map +1 -0
  48. package/dist/stepup/client.js +78 -0
  49. package/dist/stepup/client.js.map +1 -0
  50. package/dist/stepup/index.d.ts +3 -0
  51. package/dist/stepup/index.d.ts.map +1 -0
  52. package/dist/stepup/index.js +19 -0
  53. package/dist/stepup/index.js.map +1 -0
  54. package/dist/stepup/types.d.ts +35 -0
  55. package/dist/stepup/types.d.ts.map +1 -0
  56. package/dist/stepup/types.js +3 -0
  57. package/dist/stepup/types.js.map +1 -0
  58. package/package.json +13 -16
  59. package/dist/client.d.ts +0 -134
  60. package/dist/client.d.ts.map +0 -1
  61. package/dist/client.js +0 -300
  62. package/dist/client.js.map +0 -1
  63. package/dist/delegation/client.d.ts +0 -116
  64. package/dist/delegation/client.d.ts.map +0 -1
  65. package/dist/delegation/client.js +0 -227
  66. package/dist/delegation/client.js.map +0 -1
  67. package/dist/exceptions.d.ts +0 -52
  68. package/dist/exceptions.d.ts.map +0 -1
  69. package/dist/exceptions.js +0 -81
  70. package/dist/exceptions.js.map +0 -1
  71. package/dist/utils.d.ts +0 -61
  72. package/dist/utils.d.ts.map +0 -1
  73. package/dist/utils.js +0 -263
  74. package/dist/utils.js.map +0 -1
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ /**
3
+ * Secure transport for ECIES-encrypted and signed delegation requests.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DelegationTransport = void 0;
7
+ const crypto_1 = require("./crypto");
8
+ const exceptions_1 = require("./exceptions");
9
+ class DelegationTransport {
10
+ constructor(options) {
11
+ this.baseUrl = options.baseUrl.replace(/\/$/, '');
12
+ this.signer = options.signer;
13
+ this.verifier = options.verifier;
14
+ this.encryptor = options.encryptor;
15
+ this.decryptor = options.decryptor;
16
+ this.timeoutSeconds = options.timeoutSeconds ?? 15;
17
+ this.clockSkewSeconds = options.clockSkewSeconds ?? 300;
18
+ }
19
+ /**
20
+ * Send an encrypted and signed delegation request to the IDP.
21
+ */
22
+ async send(options) {
23
+ const { endpoint, payload, includeBaseUrl = true, headers: extraHeaders = {} } = options;
24
+ let encryptedEnv;
25
+ let headers;
26
+ try {
27
+ const body = Buffer.from(JSON.stringify(payload));
28
+ encryptedEnv = await this.encryptor.encrypt(body);
29
+ const ts = (0, crypto_1.nowS)();
30
+ const sig = this.signer.signDetached(encryptedEnv, ts);
31
+ headers = {
32
+ 'Content-Type': 'application/json',
33
+ 'X-Enc-Alg': 'x25519-aesgcm',
34
+ 'X-Timestamp': String(ts),
35
+ 'X-Signature-Alg': sig.alg,
36
+ 'X-Signature': sig.signatureB64,
37
+ };
38
+ if (sig.kid) {
39
+ headers['X-Key-Id'] = sig.kid;
40
+ }
41
+ Object.assign(headers, extraHeaders);
42
+ }
43
+ catch (error) {
44
+ throw new exceptions_1.DelegationRequestError('Failed to prepare secure request', { cause: error });
45
+ }
46
+ let response;
47
+ let responseData;
48
+ try {
49
+ const url = includeBaseUrl ? this.baseUrl + endpoint : endpoint;
50
+ const controller = new AbortController();
51
+ const timeoutId = setTimeout(() => controller.abort(), this.timeoutSeconds * 1000);
52
+ try {
53
+ response = await fetch(url, {
54
+ method: 'POST',
55
+ headers,
56
+ body: encryptedEnv,
57
+ signal: controller.signal,
58
+ });
59
+ }
60
+ finally {
61
+ clearTimeout(timeoutId);
62
+ }
63
+ responseData = Buffer.from(await response.arrayBuffer());
64
+ }
65
+ catch (error) {
66
+ throw new exceptions_1.DelegationRequestError('Request to IDP failed', { cause: error });
67
+ }
68
+ try {
69
+ const respSig = response.headers.get('x-signature');
70
+ const respAlg = response.headers.get('x-signature-alg');
71
+ const respKid = response.headers.get('x-key-id');
72
+ const respTsHeader = response.headers.get('x-timestamp');
73
+ if (!respSig || !respAlg || !respTsHeader) {
74
+ throw new exceptions_1.DelegationResponseError('Missing signature headers in IDP response');
75
+ }
76
+ const respTs = Number(respTsHeader);
77
+ if (!Number.isFinite(respTs)) {
78
+ throw new exceptions_1.DelegationResponseError('Invalid response timestamp');
79
+ }
80
+ const skew = Math.abs((0, crypto_1.nowS)() - respTs);
81
+ if (skew > this.clockSkewSeconds) {
82
+ throw new exceptions_1.DelegationResponseError(`Response timestamp outside allowed skew (${this.clockSkewSeconds}s)`);
83
+ }
84
+ this.verifier.verify(responseData, respTs, respSig, respAlg, respKid ?? undefined);
85
+ if (response.headers.get('x-enc-alg') !== 'x25519-aesgcm') {
86
+ throw new exceptions_1.DelegationResponseError('IDP response must be ECIES encrypted');
87
+ }
88
+ const plaintext = await this.decryptor.decrypt(responseData);
89
+ const decryptedData = JSON.parse(plaintext.toString('utf-8'));
90
+ if (response.status >= 400) {
91
+ const errorDetail = decryptedData?.detail;
92
+ const errorBody = errorDetail ? String(errorDetail) : JSON.stringify(decryptedData);
93
+ throw new exceptions_1.DelegationRequestError(`IDP returned ${response.status}`, {
94
+ statusCode: response.status,
95
+ responseBody: errorBody,
96
+ });
97
+ }
98
+ return decryptedData;
99
+ }
100
+ catch (error) {
101
+ if (error instanceof exceptions_1.DelegationRequestError) {
102
+ throw error;
103
+ }
104
+ if (error instanceof exceptions_1.DelegationResponseError) {
105
+ throw error;
106
+ }
107
+ if (response.status >= 400) {
108
+ const responseText = responseData.toString('utf-8').substring(0, 500);
109
+ throw new exceptions_1.DelegationRequestError(`IDP returned ${response.status}`, {
110
+ statusCode: response.status,
111
+ responseBody: responseText,
112
+ cause: error,
113
+ });
114
+ }
115
+ throw new exceptions_1.DelegationResponseError('Failed to process secure response', { cause: error });
116
+ }
117
+ }
118
+ }
119
+ exports.DelegationTransport = DelegationTransport;
120
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/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AE,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;CACF;AA1ID,kDA0IC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Hawcx OAuth Errors
3
+ */
4
+ /**
5
+ * Optional structured fields shared across the Hawcx OAuth error hierarchy.
6
+ * `error` is a stable machine-readable code callers can dispatch on (e.g.
7
+ * `'state_mismatch'`, `'state_missing'`, or an IdP-supplied OAuth error such as
8
+ * `'access_denied'`); `errorDescription` is the human-readable detail when one
9
+ * is available. Both are optional and never affect `.message`.
10
+ */
11
+ export interface HawcxOAuthErrorFields {
12
+ /** Machine-readable error code (e.g. `'state_mismatch'`, `'access_denied'`). */
13
+ error?: string;
14
+ /** Human-readable error description, when one is available. */
15
+ errorDescription?: string;
16
+ }
17
+ /**
18
+ * Canonical root for every Hawcx SDK error, aligned with the Java/Python SDKs
19
+ * (`HawcxError`). Catch this to handle any SDK-originated failure.
20
+ */
21
+ export declare class HawcxError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ /**
25
+ * Historical base, retained for back-compat. Now a subclass of {@link HawcxError};
26
+ * every SDK error is catchable via either. New code can catch `HawcxError`.
27
+ *
28
+ * Carries optional structured {@link HawcxOAuthErrorFields} (`error` /
29
+ * `errorDescription`) so callers can dispatch on a stable code without parsing
30
+ * `.message`. These are populated at the relevant raise sites and never alter
31
+ * the thrown message string.
32
+ */
33
+ export declare class HawcxOAuthError extends HawcxError {
34
+ /** Machine-readable error code, when set at the raise site. */
35
+ readonly error?: string;
36
+ /** Human-readable error description, when available. */
37
+ readonly errorDescription?: string;
38
+ constructor(message: string, fields?: HawcxOAuthErrorFields);
39
+ }
40
+ export declare class TokenExchangeError extends HawcxOAuthError {
41
+ readonly statusCode?: number;
42
+ constructor(message: string, statusCode?: number, fields?: HawcxOAuthErrorFields);
43
+ }
44
+ export declare class TokenVerificationError extends HawcxOAuthError {
45
+ constructor(message: string, fields?: HawcxOAuthErrorFields);
46
+ }
47
+ /**
48
+ * Thrown when OIDC discovery (`HawcxOAuth.fromIssuer`) cannot resolve a usable
49
+ * provider configuration — DNS / TLS / network failure, non-2xx response from
50
+ * `/.well-known/openid-configuration`, malformed JSON, or a discovery document
51
+ * missing required fields (`token_endpoint`, `jwks_uri`,
52
+ * `id_token_signing_alg_values_supported`).
53
+ *
54
+ * The original failure (when present) is attached as `cause`, so the full
55
+ * diagnostic stack survives.
56
+ */
57
+ export declare class DiscoveryError extends HawcxOAuthError {
58
+ constructor(message: string, options?: {
59
+ cause?: unknown;
60
+ } & HawcxOAuthErrorFields);
61
+ }
62
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAM5D;AAED,qBAAa,kBAAmB,SAAQ,eAAe;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAKjF;AAED,qBAAa,sBAAuB,SAAQ,eAAe;gBAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAI5D;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,eAAe;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,qBAAqB;CAOnF"}
package/dist/errors.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Hawcx OAuth Errors
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DiscoveryError = exports.TokenVerificationError = exports.TokenExchangeError = exports.HawcxOAuthError = exports.HawcxError = void 0;
7
+ /**
8
+ * Canonical root for every Hawcx SDK error, aligned with the Java/Python SDKs
9
+ * (`HawcxError`). Catch this to handle any SDK-originated failure.
10
+ */
11
+ class HawcxError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'HawcxError';
15
+ }
16
+ }
17
+ exports.HawcxError = HawcxError;
18
+ /**
19
+ * Historical base, retained for back-compat. Now a subclass of {@link HawcxError};
20
+ * every SDK error is catchable via either. New code can catch `HawcxError`.
21
+ *
22
+ * Carries optional structured {@link HawcxOAuthErrorFields} (`error` /
23
+ * `errorDescription`) so callers can dispatch on a stable code without parsing
24
+ * `.message`. These are populated at the relevant raise sites and never alter
25
+ * the thrown message string.
26
+ */
27
+ class HawcxOAuthError extends HawcxError {
28
+ constructor(message, fields) {
29
+ super(message);
30
+ this.name = 'HawcxOAuthError';
31
+ if (fields?.error !== undefined)
32
+ this.error = fields.error;
33
+ if (fields?.errorDescription !== undefined)
34
+ this.errorDescription = fields.errorDescription;
35
+ }
36
+ }
37
+ exports.HawcxOAuthError = HawcxOAuthError;
38
+ class TokenExchangeError extends HawcxOAuthError {
39
+ constructor(message, statusCode, fields) {
40
+ super(message, fields);
41
+ this.name = 'TokenExchangeError';
42
+ this.statusCode = statusCode;
43
+ }
44
+ }
45
+ exports.TokenExchangeError = TokenExchangeError;
46
+ class TokenVerificationError extends HawcxOAuthError {
47
+ constructor(message, fields) {
48
+ super(message, fields);
49
+ this.name = 'TokenVerificationError';
50
+ }
51
+ }
52
+ exports.TokenVerificationError = TokenVerificationError;
53
+ /**
54
+ * Thrown when OIDC discovery (`HawcxOAuth.fromIssuer`) cannot resolve a usable
55
+ * provider configuration — DNS / TLS / network failure, non-2xx response from
56
+ * `/.well-known/openid-configuration`, malformed JSON, or a discovery document
57
+ * missing required fields (`token_endpoint`, `jwks_uri`,
58
+ * `id_token_signing_alg_values_supported`).
59
+ *
60
+ * The original failure (when present) is attached as `cause`, so the full
61
+ * diagnostic stack survives.
62
+ */
63
+ class DiscoveryError extends HawcxOAuthError {
64
+ constructor(message, options) {
65
+ super(message, options);
66
+ this.name = 'DiscoveryError';
67
+ if (options?.cause !== undefined) {
68
+ this.cause = options.cause;
69
+ }
70
+ }
71
+ }
72
+ exports.DiscoveryError = DiscoveryError;
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAgBH;;;GAGG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AALD,gCAKC;AAED;;;;;;;;GAQG;AACH,MAAa,eAAgB,SAAQ,UAAU;IAM7C,YAAY,OAAe,EAAE,MAA8B;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,MAAM,EAAE,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3D,IAAI,MAAM,EAAE,gBAAgB,KAAK,SAAS;YAAE,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAC9F,CAAC;CACF;AAZD,0CAYC;AAED,MAAa,kBAAmB,SAAQ,eAAe;IAGrD,YAAY,OAAe,EAAE,UAAmB,EAAE,MAA8B;QAC9E,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AARD,gDAQC;AAED,MAAa,sBAAuB,SAAQ,eAAe;IACzD,YAAY,OAAe,EAAE,MAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AALD,wDAKC;AAED;;;;;;;;;GASG;AACH,MAAa,cAAe,SAAQ,eAAe;IACjD,YAAY,OAAe,EAAE,OAAqD;QAChF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAA4B,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AARD,wCAQC"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,23 @@
1
1
  /**
2
2
  * Hawcx OAuth Client SDK
3
3
  *
4
- * A lightweight, production-ready Node.js library for exchanging OAuth authorization
5
- * codes and verifying JWT claims. Built with security, reliability, and ease of use in mind.
4
+ * Simple, production-ready SDK for exchanging authorization codes
5
+ * and verifying JWT tokens with Hawcx OAuth service.
6
6
  *
7
7
  * @example
8
8
  * ```typescript
9
- * import { exchangeCodeForClaims } from '@hawcx/oauth-client';
9
+ * import { HawcxOAuth } from '@hawcx/oauth-client';
10
10
  *
11
- * const claims = await exchangeCodeForClaims({
12
- * code: 'abc123',
13
- * oauthTokenUrl: 'https://oauth.example.com/token',
14
- * clientId: 'my-app',
15
- * publicKey: 'path/to/public.pem'
16
- * });
17
- * console.log(claims.sub); // 'user@example.com'
11
+ * const oauth = new HawcxOAuth({ configId: 'your-api-key' });
12
+ * const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
18
13
  * ```
19
14
  */
20
- export { exchangeCodeForClaims, exchangeCodeForTokenAndClaims, verifyJwt, } from './client';
21
- export type { ExchangeCodeOptions, VerifyJwtOptions } from './client';
22
- export { fetchJwks, getKeyFromJwks } from './utils';
23
- export { HawcxOAuthError, InvalidPublicKeyError, OAuthExchangeError, JWTVerificationError, } from './exceptions';
15
+ export { HawcxOAuth } from './oauth';
16
+ export type { HawcxOAuthConfig, HawcxOAuthIssuerConfig, ExchangeResult, JwtClaims, DiscoveryMetadata, VerifyTokenOptions, } from './oauth';
17
+ export { HawcxError, HawcxOAuthError, TokenExchangeError, TokenVerificationError, DiscoveryError, } from './errors';
18
+ export type { HawcxOAuthErrorFields } from './errors';
19
+ export { ClientAssertionSigner, CLIENT_ASSERTION_TYPE } from './client-assertion';
24
20
  export * from './delegation';
25
- export declare const VERSION = "0.1.0";
21
+ export * from './stepup';
22
+ export declare const VERSION = "5.1.0";
26
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,SAAS,GACV,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGtE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAGtB,cAAc,cAAc,CAAC;AAE7B,eAAO,MAAM,OAAO,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EACV,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGlF,cAAc,cAAc,CAAC;AAG7B,cAAc,UAAU,CAAC;AAEzB,eAAO,MAAM,OAAO,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -2,20 +2,15 @@
2
2
  /**
3
3
  * Hawcx OAuth Client SDK
4
4
  *
5
- * A lightweight, production-ready Node.js library for exchanging OAuth authorization
6
- * codes and verifying JWT claims. Built with security, reliability, and ease of use in mind.
5
+ * Simple, production-ready SDK for exchanging authorization codes
6
+ * and verifying JWT tokens with Hawcx OAuth service.
7
7
  *
8
8
  * @example
9
9
  * ```typescript
10
- * import { exchangeCodeForClaims } from '@hawcx/oauth-client';
10
+ * import { HawcxOAuth } from '@hawcx/oauth-client';
11
11
  *
12
- * const claims = await exchangeCodeForClaims({
13
- * code: 'abc123',
14
- * oauthTokenUrl: 'https://oauth.example.com/token',
15
- * clientId: 'my-app',
16
- * publicKey: 'path/to/public.pem'
17
- * });
18
- * console.log(claims.sub); // 'user@example.com'
12
+ * const oauth = new HawcxOAuth({ configId: 'your-api-key' });
13
+ * const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
19
14
  * ```
20
15
  */
21
16
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -33,23 +28,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
33
28
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
34
29
  };
35
30
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.VERSION = exports.JWTVerificationError = exports.OAuthExchangeError = exports.InvalidPublicKeyError = exports.HawcxOAuthError = exports.getKeyFromJwks = exports.fetchJwks = exports.verifyJwt = exports.exchangeCodeForTokenAndClaims = exports.exchangeCodeForClaims = void 0;
37
- // Core OAuth client
38
- var client_1 = require("./client");
39
- Object.defineProperty(exports, "exchangeCodeForClaims", { enumerable: true, get: function () { return client_1.exchangeCodeForClaims; } });
40
- Object.defineProperty(exports, "exchangeCodeForTokenAndClaims", { enumerable: true, get: function () { return client_1.exchangeCodeForTokenAndClaims; } });
41
- Object.defineProperty(exports, "verifyJwt", { enumerable: true, get: function () { return client_1.verifyJwt; } });
42
- // JWKS utilities
43
- var utils_1 = require("./utils");
44
- Object.defineProperty(exports, "fetchJwks", { enumerable: true, get: function () { return utils_1.fetchJwks; } });
45
- Object.defineProperty(exports, "getKeyFromJwks", { enumerable: true, get: function () { return utils_1.getKeyFromJwks; } });
46
- // Exceptions
47
- var exceptions_1 = require("./exceptions");
48
- Object.defineProperty(exports, "HawcxOAuthError", { enumerable: true, get: function () { return exceptions_1.HawcxOAuthError; } });
49
- Object.defineProperty(exports, "InvalidPublicKeyError", { enumerable: true, get: function () { return exceptions_1.InvalidPublicKeyError; } });
50
- Object.defineProperty(exports, "OAuthExchangeError", { enumerable: true, get: function () { return exceptions_1.OAuthExchangeError; } });
51
- Object.defineProperty(exports, "JWTVerificationError", { enumerable: true, get: function () { return exceptions_1.JWTVerificationError; } });
31
+ exports.VERSION = exports.CLIENT_ASSERTION_TYPE = exports.ClientAssertionSigner = exports.DiscoveryError = exports.TokenVerificationError = exports.TokenExchangeError = exports.HawcxOAuthError = exports.HawcxError = exports.HawcxOAuth = void 0;
32
+ var oauth_1 = require("./oauth");
33
+ Object.defineProperty(exports, "HawcxOAuth", { enumerable: true, get: function () { return oauth_1.HawcxOAuth; } });
34
+ var errors_1 = require("./errors");
35
+ Object.defineProperty(exports, "HawcxError", { enumerable: true, get: function () { return errors_1.HawcxError; } });
36
+ Object.defineProperty(exports, "HawcxOAuthError", { enumerable: true, get: function () { return errors_1.HawcxOAuthError; } });
37
+ Object.defineProperty(exports, "TokenExchangeError", { enumerable: true, get: function () { return errors_1.TokenExchangeError; } });
38
+ Object.defineProperty(exports, "TokenVerificationError", { enumerable: true, get: function () { return errors_1.TokenVerificationError; } });
39
+ Object.defineProperty(exports, "DiscoveryError", { enumerable: true, get: function () { return errors_1.DiscoveryError; } });
40
+ var client_assertion_1 = require("./client-assertion");
41
+ Object.defineProperty(exports, "ClientAssertionSigner", { enumerable: true, get: function () { return client_assertion_1.ClientAssertionSigner; } });
42
+ Object.defineProperty(exports, "CLIENT_ASSERTION_TYPE", { enumerable: true, get: function () { return client_assertion_1.CLIENT_ASSERTION_TYPE; } });
52
43
  // Delegation module
53
44
  __exportStar(require("./delegation"), exports);
54
- exports.VERSION = '0.1.0';
45
+ // Step-up module
46
+ __exportStar(require("./stepup"), exports);
47
+ exports.VERSION = '5.1.0';
55
48
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;;;;;;;;;AAEH,oBAAoB;AACpB,mCAIkB;AAHhB,+GAAA,qBAAqB,OAAA;AACrB,uHAAA,6BAA6B,OAAA;AAC7B,mGAAA,SAAS,OAAA;AAIX,iBAAiB;AACjB,iCAAoD;AAA3C,kGAAA,SAAS,OAAA;AAAE,uGAAA,cAAc,OAAA;AAElC,aAAa;AACb,2CAKsB;AAJpB,6GAAA,eAAe,OAAA;AACf,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,kHAAA,oBAAoB,OAAA;AAGtB,oBAAoB;AACpB,+CAA6B;AAEhB,QAAA,OAAO,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;AAEH,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AASnB,mCAMkB;AALhB,oGAAA,UAAU,OAAA;AACV,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,gHAAA,sBAAsB,OAAA;AACtB,wGAAA,cAAc,OAAA;AAIhB,uDAAkF;AAAzE,yHAAA,qBAAqB,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAErD,oBAAoB;AACpB,+CAA6B;AAE7B,iBAAiB;AACjB,2CAAyB;AAEZ,QAAA,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Hawcx OAuth Client
3
+ *
4
+ * Two construction paths:
5
+ *
6
+ * 1. OIDC discovery (recommended) — `HawcxOAuth.fromIssuer(...)` fetches
7
+ * `<issuer>/.well-known/openid-configuration` once at startup and wires
8
+ * up a verifier that enforces signature + iss + aud + exp + nbf on every
9
+ * subsequent `verifyToken` call.
10
+ *
11
+ * 2. Legacy — `new HawcxOAuth({ configId, baseUrl })` hits the fixed
12
+ * endpoints `/oauth2/token` and `/keys` directly. Backward-compatible
13
+ * with v4.x callers, but does NOT verify `iss` or `aud` — the JWT's
14
+ * signature is the only check.
15
+ *
16
+ * Both modes are safe to share across requests.
17
+ */
18
+ import { type JWTPayload } from 'jose';
19
+ import { ClientAssertionSigner } from './client-assertion';
20
+ export interface HawcxOAuthConfig {
21
+ /** Your Hawcx config-id (sent as the `X-Config-Id` header on token exchange) */
22
+ configId: string;
23
+ /** Base URL override (default: https://api.hawcx.com) */
24
+ baseUrl?: string;
25
+ /** Request timeout in ms (default: 10000) */
26
+ timeout?: number;
27
+ /**
28
+ * Tolerated clock skew in seconds when verifying `exp` and `nbf` claims.
29
+ * Default 10. Set to 0 to require exact-time validation; raise above 10
30
+ * if you regularly see NTP drift between the issuer and this host.
31
+ * Spec.md §3.3.
32
+ */
33
+ clockToleranceSeconds?: number;
34
+ }
35
+ /**
36
+ * Options for the discovery-mode factory.
37
+ *
38
+ * **configId vs clientId.** Hawcx separates the tenant routing key from the
39
+ * audience claim — the SDK forwards each to the right place:
40
+ *
41
+ * - `configId` — opaque per-tenant routing key. Sent verbatim as the
42
+ * `X-Config-Id` header on the token-exchange POST so the OAuth server can
43
+ * look up the tenant.
44
+ * - `clientId` — whatever value the tenant has configured (in the Hawcx admin
45
+ * console) as the `aud` claim on issued id_tokens. The verifier checks the
46
+ * token's `aud` against this exact string.
47
+ *
48
+ * Passing the same value for both fails verification with an audience-mismatch
49
+ * error unless the tenant has configured them identically.
50
+ */
51
+ export interface HawcxOAuthIssuerConfig {
52
+ /** Hawcx issuer URL (e.g. `https://api.hawcx.com`). Used for OIDC discovery and as the expected `iss` claim. */
53
+ issuer: string;
54
+ /** Hawcx tenant config-id; sent as the `X-Config-Id` header on token exchange. */
55
+ configId: string;
56
+ /** Hawcx project / tenant client-id; matched as the expected `aud` claim on id_tokens. */
57
+ clientId: string;
58
+ /** Per-request timeout in ms for token exchange and JWKS fetch (default: 10000) */
59
+ timeout?: number;
60
+ /** Timeout in ms for the one-shot discovery fetch (default: 5000) */
61
+ discoveryTimeout?: number;
62
+ /**
63
+ * Tolerated clock skew in seconds when verifying `exp` and `nbf` claims.
64
+ * Default 10. Set to 0 to require exact-time validation; raise above 10
65
+ * if you regularly see NTP drift between the issuer and this host.
66
+ * Spec.md §3.3.
67
+ */
68
+ clockToleranceSeconds?: number;
69
+ }
70
+ export interface JwtClaims extends JWTPayload {
71
+ /** Subject (user ID) */
72
+ sub?: string;
73
+ /** Issuer */
74
+ iss?: string;
75
+ /** Audience */
76
+ aud?: string | string[];
77
+ /** Issued at (unix timestamp) */
78
+ iat?: number;
79
+ /** Expiration (unix timestamp) */
80
+ exp?: number;
81
+ /** Not before (unix timestamp) */
82
+ nbf?: number;
83
+ /** JWT ID */
84
+ jti?: string;
85
+ /** Nonce */
86
+ nonce?: string;
87
+ /** Authentication methods */
88
+ amr?: string[];
89
+ /** MFA method used */
90
+ mfa_method?: string;
91
+ /** Email */
92
+ email?: string;
93
+ /** Name */
94
+ name?: string;
95
+ }
96
+ export interface ExchangeResult {
97
+ /** Raw id_token JWT */
98
+ idToken: string;
99
+ /** Verified JWT claims */
100
+ claims: JwtClaims;
101
+ }
102
+ /**
103
+ * Subset of the OIDC discovery document the SDK actually consumes.
104
+ * The raw response may include additional fields; they're preserved on
105
+ * `HawcxOAuth.discoveryMetadata` but the SDK only relies on these.
106
+ */
107
+ export interface DiscoveryMetadata {
108
+ issuer: string;
109
+ token_endpoint: string;
110
+ jwks_uri: string;
111
+ id_token_signing_alg_values_supported: string[];
112
+ [key: string]: unknown;
113
+ }
114
+ export interface VerifyTokenOptions {
115
+ /**
116
+ * If set, the JWT's `nonce` claim must equal this value. Use when your
117
+ * authorization request bound a nonce. Checked in both discovery and
118
+ * legacy modes — legacy mode skips `iss` / `aud` but the explicit nonce
119
+ * comparison applies unconditionally when this option is provided.
120
+ */
121
+ nonce?: string;
122
+ }
123
+ /**
124
+ * Hawcx OAuth Client
125
+ *
126
+ * Discovery-mode usage (recommended):
127
+ *
128
+ * ```typescript
129
+ * const oauth = await HawcxOAuth.fromIssuer({
130
+ * issuer: 'https://api.hawcx.com',
131
+ * configId: process.env.HAWCX_CONFIG_ID!,
132
+ * clientId: process.env.HAWCX_CLIENT_ID!,
133
+ * });
134
+ * const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
135
+ * ```
136
+ *
137
+ * Legacy usage (no discovery; aud/iss are not checked):
138
+ *
139
+ * ```typescript
140
+ * const oauth = new HawcxOAuth({ configId: process.env.HAWCX_CONFIG_ID! });
141
+ * const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
142
+ * ```
143
+ */
144
+ export declare class HawcxOAuth {
145
+ private readonly configId;
146
+ private readonly tokenEndpoint;
147
+ private readonly jwksUrl;
148
+ private readonly timeout;
149
+ private readonly clockToleranceSeconds;
150
+ /** Expected `aud` claim. `null` in legacy mode (audience is not checked). */
151
+ private readonly expectedAudience;
152
+ /** Expected `iss` claim. `null` in legacy mode (issuer is not checked). */
153
+ private readonly expectedIssuer;
154
+ /**
155
+ * id_token signing algorithms accepted by `verifyToken`. In discovery mode
156
+ * this is the intersection of the issuer's advertised algs with the SDK's
157
+ * closed allowlist ({@link DEFAULT_ID_TOKEN_ALGS}). `null` in legacy mode
158
+ * (we have no discovery doc to constrain against, so jose's default
159
+ * "accept whatever the JWKS provides" remains — same as 4.x).
160
+ */
161
+ private readonly allowedAlgorithms;
162
+ /** Resolved OIDC discovery document. `null` in legacy mode. */
163
+ readonly discoveryMetadata: DiscoveryMetadata | null;
164
+ private jwks;
165
+ /**
166
+ * Optional `private_key_jwt` signer (discovery mode only). `null` ⇒ the
167
+ * token exchange stays public-client + PKCE. Set via {@link withClientAssertion},
168
+ * which returns a *new* configured client (this field is `readonly`).
169
+ */
170
+ private readonly clientAssertionSigner;
171
+ /**
172
+ * Construct a legacy-mode client. For discovery mode, prefer
173
+ * {@link HawcxOAuth.fromIssuer}.
174
+ */
175
+ constructor(config: HawcxOAuthConfig);
176
+ /**
177
+ * Construct a client via OIDC discovery.
178
+ *
179
+ * Fetches `<issuer>/.well-known/openid-configuration`, reads the token
180
+ * endpoint, JWKS URI, and supported id_token signing algorithm, and wires
181
+ * a verifier that enforces signature + `iss` + `aud` + `exp` + `nbf` on
182
+ * subsequent {@link verifyToken} calls.
183
+ *
184
+ * **Discovery is bounded** at `discoveryTimeout` ms (default 5000) so an
185
+ * unreachable issuer fails fast with {@link DiscoveryError} rather than
186
+ * hanging your bootstrap.
187
+ *
188
+ * @throws {DiscoveryError} if discovery fails to resolve or the document
189
+ * is missing required fields (`token_endpoint`, `jwks_uri`,
190
+ * `id_token_signing_alg_values_supported`).
191
+ */
192
+ static fromIssuer(config: HawcxOAuthIssuerConfig): Promise<HawcxOAuth>;
193
+ /**
194
+ * Opt into `private_key_jwt` client authentication (discovery mode only).
195
+ * When set, the token exchange signs and attaches an RFC 7523
196
+ * `client_assertion` (in addition to PKCE). Without it, the exchange stays
197
+ * public-client + PKCE.
198
+ *
199
+ * Intended to be called once right after {@link fromIssuer}, before the
200
+ * client is shared. Returns `this` for chaining.
201
+ */
202
+ /**
203
+ * @beta Experimental `private_key_jwt` surface; may change before stable.
204
+ *
205
+ * Returns a **new** discovery-mode client configured with the signer (sharing
206
+ * this client's resolved discovery state); the original is unchanged, so a
207
+ * configured client is immutable. Chained usage
208
+ * (`(await fromIssuer(...)).withClientAssertion(...)`) is unaffected.
209
+ *
210
+ * Refuses if the OP's discovery doc advertises
211
+ * `token_endpoint_auth_methods_supported` without `private_key_jwt`
212
+ * (the assertion would be silently ignored).
213
+ */
214
+ withClientAssertion(signer: ClientAssertionSigner): HawcxOAuth;
215
+ /**
216
+ * Exchange authorization code for id_token and verified claims.
217
+ *
218
+ * @param code - Authorization code from auth flow
219
+ * @param codeVerifier - PKCE code verifier
220
+ * @param redirectUri - Optional. If your original authorization request
221
+ * registered a `redirect_uri`, RFC 6749 §4.1.3 requires the token
222
+ * request to carry the same value. Omit if the auth request also omitted it.
223
+ * @param expectedNonce - Optional. If your authorization request bound a
224
+ * `nonce`, pass it here so the returned id_token's `nonce` is verified.
225
+ * Required whenever the token carries a nonce (verification refuses
226
+ * otherwise — OIDC Core §3.1.3.7).
227
+ */
228
+ exchangeCode(code: string, codeVerifier: string, redirectUri?: string, expectedNonce?: string): Promise<ExchangeResult>;
229
+ /**
230
+ * Verify a JWT token and return its claims.
231
+ *
232
+ * In **discovery mode**, enforces signature + `iss` + `aud` + `exp` + `nbf`
233
+ * (and the optional `nonce` claim if `options.nonce` is provided).
234
+ *
235
+ * In **legacy mode**, only the signature is verified. Audience and issuer
236
+ * claims are not checked, matching the pre-5.x behavior.
237
+ */
238
+ verifyToken(token: string, options?: VerifyTokenOptions): Promise<JwtClaims>;
239
+ /**
240
+ * Get or create the remote JWKS. jose handles caching + concurrent-fetch
241
+ * coalescing internally.
242
+ *
243
+ * No single-flight guard is needed here: this method is fully synchronous
244
+ * (no `await` between the null-check and the assignment), so within Node's
245
+ * single-threaded event loop the first caller assigns `this.jwks` before any
246
+ * other code runs. Two concurrent `verifyToken` calls therefore cannot create
247
+ * duplicate `RemoteJWKSet` instances.
248
+ */
249
+ private getJwks;
250
+ /**
251
+ * Drop the cached JWKS so the next `verifyToken` re-fetches it. Useful after
252
+ * an operator-triggered signing-key rotation, or in tests.
253
+ *
254
+ * Canonical name, aligned with the Java (`refreshJwks`) and Python
255
+ * (`refresh_jwks`) SDKs.
256
+ */
257
+ refreshJwks(): void;
258
+ /**
259
+ * @deprecated since 5.1.0 — renamed to {@link refreshJwks} for cross-SDK
260
+ * consistency. Will be removed in 6.0.0. Behaviour is identical.
261
+ */
262
+ clearCache(): void;
263
+ private clearCacheWarned;
264
+ }
265
+ //# sourceMappingURL=oauth.d.ts.map