axiam-sdk 1.0.0-alpha19 → 1.0.0-alpha21
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 +155 -4
- package/dist/amqp/index.d.cts +1 -1
- package/dist/amqp/index.d.ts +1 -1
- package/dist/amqp/index.js +4 -0
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +4 -0
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-CcTdIf78.d.ts → authzCore-DtSN59if.d.ts} +2 -2
- package/dist/{authzCore-B7GSd3-t.d.cts → authzCore-DuRI1aJf.d.cts} +2 -2
- package/dist/client-B_FqmZ0i.d.cts +72 -0
- package/dist/client-Dn1fs5MH.d.ts +72 -0
- package/dist/cookieJar-BTDnjjbL.d.cts +122 -0
- package/dist/cookieJar-Cl8Lq9dL.d.ts +122 -0
- package/dist/grpc/index.d.cts +6 -5
- package/dist/grpc/index.d.ts +6 -5
- package/dist/grpc/index.js +178 -4
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +178 -4
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +76 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -4
- package/dist/index.mjs.map +1 -1
- package/dist/jwks-BgojMGC5.d.cts +152 -0
- package/dist/jwks-BgojMGC5.d.ts +152 -0
- package/dist/middleware/index.d.cts +194 -4
- package/dist/middleware/index.d.ts +194 -4
- package/dist/middleware/index.js +1107 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +1100 -3
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +2 -2
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +3 -0
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +3 -0
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +50 -113
- package/dist/node/index.d.ts +50 -113
- package/dist/node/index.js +873 -4
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +857 -5
- package/dist/node/index.mjs.map +1 -1
- package/dist/oidcState-BGxqWUun.d.cts +598 -0
- package/dist/oidcState-CkFuCjpM.d.ts +598 -0
- package/dist/rest/index.d.cts +107 -5
- package/dist/rest/index.d.ts +107 -5
- package/dist/rest/index.js +76 -3
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +71 -4
- package/dist/rest/index.mjs.map +1 -1
- package/dist/sensitive-BC_s7Rrd.d.cts +39 -0
- package/dist/sensitive-BC_s7Rrd.d.ts +39 -0
- package/dist/{client-Co_baHgU.d.ts → session-BWUWhhyB.d.cts} +1 -70
- package/dist/{client-CzhzwRGg.d.cts → session-BWUWhhyB.d.ts} +1 -70
- package/package.json +2 -2
- package/dist/jwks-B8dPy2c6.d.cts +0 -36
- package/dist/jwks-B8dPy2c6.d.ts +0 -36
- package/dist/sensitive-CWBH_tHr.d.cts +0 -12
- package/dist/sensitive-CWBH_tHr.d.ts +0 -12
package/dist/grpc/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import * as grpc2 from '@grpc/grpc-js';
|
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { CookieJar } from 'tough-cookie';
|
|
4
4
|
import { wrapper } from 'axios-cookiejar-support';
|
|
5
|
+
import { timingSafeEqual } from 'crypto';
|
|
5
6
|
|
|
6
7
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
8
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -32,14 +33,40 @@ var AxiamError = class extends Error {
|
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
var AuthError = class _AuthError extends AxiamError {
|
|
35
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Optional stable, machine-readable reason code for the failure.
|
|
38
|
+
*
|
|
39
|
+
* Populated by the CONTRACT.md §12.4 ID-token validation checklist with
|
|
40
|
+
* one of the seven codes §12.3 rule 3 enumerates (see
|
|
41
|
+
* {@link IdTokenFailureReason}); `undefined` for every other `AuthError`.
|
|
42
|
+
* It is a *code*, never free text, so callers can branch on it without
|
|
43
|
+
* parsing `message`.
|
|
44
|
+
*/
|
|
45
|
+
reason;
|
|
46
|
+
constructor(message, reason) {
|
|
36
47
|
super(message);
|
|
37
48
|
this.name = "AuthError";
|
|
49
|
+
this.reason = reason;
|
|
38
50
|
Object.setPrototypeOf(this, _AuthError.prototype);
|
|
39
51
|
}
|
|
40
52
|
};
|
|
53
|
+
var OAuthProtocolError = class _OAuthProtocolError extends AuthError {
|
|
54
|
+
/** The RFC 6749 `error` code (e.g. `"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`). */
|
|
55
|
+
error;
|
|
56
|
+
/** The server's human-readable `error_description`. Never contains token material. */
|
|
57
|
+
errorDescription;
|
|
58
|
+
constructor(error, errorDescription) {
|
|
59
|
+
super(`${error}: ${errorDescription}`);
|
|
60
|
+
this.name = "OAuthProtocolError";
|
|
61
|
+
this.error = error;
|
|
62
|
+
this.errorDescription = errorDescription;
|
|
63
|
+
Object.setPrototypeOf(this, _OAuthProtocolError.prototype);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
41
66
|
var AuthzError = class _AuthzError extends AxiamError {
|
|
67
|
+
/** The denied action, when the server reported it. */
|
|
42
68
|
action;
|
|
69
|
+
/** The resource the denied action targeted, when the server reported it. */
|
|
43
70
|
resourceId;
|
|
44
71
|
constructor(message, action, resourceId) {
|
|
45
72
|
super(message);
|
|
@@ -50,6 +77,7 @@ var AuthzError = class _AuthzError extends AxiamError {
|
|
|
50
77
|
}
|
|
51
78
|
};
|
|
52
79
|
var NetworkError = class _NetworkError extends AxiamError {
|
|
80
|
+
/** The underlying transport error, with every non-allowlisted response header redacted (§2, X-3). */
|
|
53
81
|
cause;
|
|
54
82
|
constructor(message, cause) {
|
|
55
83
|
super(message);
|
|
@@ -73,6 +101,24 @@ function extractAuthzFieldsFromBody(body) {
|
|
|
73
101
|
const resourceId = typeof record.resource_id === "string" ? record.resource_id : void 0;
|
|
74
102
|
return { action, resourceId };
|
|
75
103
|
}
|
|
104
|
+
var OAUTH2_PATH_PREFIX = "/oauth2/";
|
|
105
|
+
function isOAuth2EndpointUrl(url) {
|
|
106
|
+
if (!url) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
return new URL(url).pathname.startsWith(OAUTH2_PATH_PREFIX);
|
|
111
|
+
} catch {
|
|
112
|
+
return url.startsWith(OAUTH2_PATH_PREFIX) || url.includes(OAUTH2_PATH_PREFIX);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function isOAuth2ErrorBody(body) {
|
|
116
|
+
if (body === null || typeof body !== "object") {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const record = body;
|
|
120
|
+
return typeof record.error === "string" && typeof record.error_description === "string";
|
|
121
|
+
}
|
|
76
122
|
var SAFE_RESPONSE_HEADERS = /* @__PURE__ */ new Set([
|
|
77
123
|
"content-type",
|
|
78
124
|
"content-length",
|
|
@@ -110,6 +156,9 @@ function sanitizeAxiosError(err) {
|
|
|
110
156
|
};
|
|
111
157
|
}
|
|
112
158
|
function mapHttpStatusToError(status, message, ctx) {
|
|
159
|
+
if ((status === 400 || status === 401) && isOAuth2EndpointUrl(ctx?.url) && isOAuth2ErrorBody(ctx?.body)) {
|
|
160
|
+
return new OAuthProtocolError(ctx.body.error, ctx.body.error_description);
|
|
161
|
+
}
|
|
113
162
|
if (status === 401) {
|
|
114
163
|
return new AuthError(message);
|
|
115
164
|
}
|
|
@@ -134,6 +183,7 @@ var REDACTED = "[SENSITIVE]";
|
|
|
134
183
|
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
135
184
|
var Sensitive = class {
|
|
136
185
|
#value;
|
|
186
|
+
/** Wrap `value` so it can never be logged or serialized by accident. */
|
|
137
187
|
constructor(value) {
|
|
138
188
|
this.#value = value;
|
|
139
189
|
}
|
|
@@ -141,12 +191,15 @@ var Sensitive = class {
|
|
|
141
191
|
expose() {
|
|
142
192
|
return this.#value;
|
|
143
193
|
}
|
|
194
|
+
/** Returns the `"[SENSITIVE]"` placeholder — never the wrapped value. */
|
|
144
195
|
toString() {
|
|
145
196
|
return REDACTED;
|
|
146
197
|
}
|
|
198
|
+
/** Makes `JSON.stringify()` emit the `"[SENSITIVE]"` placeholder. */
|
|
147
199
|
toJSON() {
|
|
148
200
|
return REDACTED;
|
|
149
201
|
}
|
|
202
|
+
/** Makes `console.log`/`util.inspect` print the `"[SENSITIVE]"` placeholder. */
|
|
150
203
|
[NODE_INSPECT_CUSTOM]() {
|
|
151
204
|
return REDACTED;
|
|
152
205
|
}
|
|
@@ -622,7 +675,14 @@ function createSession(options) {
|
|
|
622
675
|
}
|
|
623
676
|
|
|
624
677
|
// src/rest/interceptors.ts
|
|
625
|
-
var SKIP_REFRESH = [
|
|
678
|
+
var SKIP_REFRESH = [
|
|
679
|
+
"/api/v1/auth/refresh",
|
|
680
|
+
"/api/v1/auth/login",
|
|
681
|
+
"/api/v1/auth/logout",
|
|
682
|
+
"/oauth2/token",
|
|
683
|
+
"/oauth2/introspect",
|
|
684
|
+
"/oauth2/revoke"
|
|
685
|
+
];
|
|
626
686
|
function installCsrfInterceptor(axiosInstance, session) {
|
|
627
687
|
axiosInstance.interceptors.request.use((config) => {
|
|
628
688
|
if (session.isForeignHost(config.url)) {
|
|
@@ -654,6 +714,7 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
654
714
|
try {
|
|
655
715
|
await session.refreshGuard(async () => {
|
|
656
716
|
await session.axios.post("/api/v1/auth/refresh", session.buildRefreshBody());
|
|
717
|
+
await session.onAuthenticated?.();
|
|
657
718
|
});
|
|
658
719
|
return axiosInstance(originalRequest);
|
|
659
720
|
} catch (refreshError) {
|
|
@@ -667,7 +728,13 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
667
728
|
}
|
|
668
729
|
}
|
|
669
730
|
if (status === 401 && isSkipRefresh) {
|
|
670
|
-
return Promise.reject(
|
|
731
|
+
return Promise.reject(
|
|
732
|
+
mapHttpStatusToError(401, "authentication failed", {
|
|
733
|
+
url,
|
|
734
|
+
body: error.response.data,
|
|
735
|
+
cause: error
|
|
736
|
+
})
|
|
737
|
+
);
|
|
671
738
|
}
|
|
672
739
|
return Promise.reject(error);
|
|
673
740
|
}
|
|
@@ -747,6 +814,7 @@ async function verifyMfa(client, mfaToken, code) {
|
|
|
747
814
|
async function refresh(client) {
|
|
748
815
|
try {
|
|
749
816
|
await client.session.axios.post(REFRESH_PATH, client.session.buildRefreshBody());
|
|
817
|
+
await client.session.onAuthenticated?.();
|
|
750
818
|
} catch (err) {
|
|
751
819
|
const status = extractAxiosStatus(err);
|
|
752
820
|
if (status !== void 0) {
|
|
@@ -1004,17 +1072,84 @@ function decodeJwtPayload(token) {
|
|
|
1004
1072
|
return {};
|
|
1005
1073
|
}
|
|
1006
1074
|
}
|
|
1075
|
+
var MAX_CLOCK_SKEW_SEC = 60;
|
|
1076
|
+
function idTokenAuthError(reason, message) {
|
|
1077
|
+
return new AuthError(`id_token validation failed (${reason}): ${message}`, reason);
|
|
1078
|
+
}
|
|
1079
|
+
function resolveClockSkewSec(clockSkewSec) {
|
|
1080
|
+
if (clockSkewSec === void 0) {
|
|
1081
|
+
return MAX_CLOCK_SKEW_SEC;
|
|
1082
|
+
}
|
|
1083
|
+
return Math.min(Math.max(clockSkewSec, 0), MAX_CLOCK_SKEW_SEC);
|
|
1084
|
+
}
|
|
1085
|
+
function constantTimeEquals(a, b) {
|
|
1086
|
+
const left = Buffer.from(a, "utf8");
|
|
1087
|
+
const right = Buffer.from(b, "utf8");
|
|
1088
|
+
if (left.length !== right.length) {
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
return timingSafeEqual(left, right);
|
|
1092
|
+
}
|
|
1093
|
+
var ID_TOKEN_ALG = "EdDSA";
|
|
1094
|
+
function assertIdTokenAlg(alg) {
|
|
1095
|
+
if (alg !== ID_TOKEN_ALG) {
|
|
1096
|
+
throw idTokenAuthError(
|
|
1097
|
+
"invalid_alg",
|
|
1098
|
+
`expected alg "${ID_TOKEN_ALG}", got ${typeof alg === "string" ? `"${alg}"` : "no alg header"}`
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
function checkIdTokenClaims(claims, expectations, nowSec = Math.floor(Date.now() / 1e3)) {
|
|
1103
|
+
const skew = resolveClockSkewSec(expectations.clockSkewSec);
|
|
1104
|
+
if (claims.iss !== expectations.issuer) {
|
|
1105
|
+
throw idTokenAuthError("invalid_issuer", "iss does not equal the discovery document issuer");
|
|
1106
|
+
}
|
|
1107
|
+
const audiences = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
|
|
1108
|
+
if (!audiences.includes(expectations.clientId)) {
|
|
1109
|
+
throw idTokenAuthError("invalid_audience", "aud does not contain this client_id");
|
|
1110
|
+
}
|
|
1111
|
+
if (audiences.length > 1 && claims.azp !== expectations.clientId) {
|
|
1112
|
+
throw idTokenAuthError(
|
|
1113
|
+
"invalid_audience",
|
|
1114
|
+
"aud holds multiple audiences and azp is absent or does not equal this client_id"
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
if (typeof claims.exp !== "number") {
|
|
1118
|
+
throw idTokenAuthError("token_expired", "exp claim is missing or not a number");
|
|
1119
|
+
}
|
|
1120
|
+
if (claims.exp + skew <= nowSec) {
|
|
1121
|
+
throw idTokenAuthError("token_expired", "exp is in the past");
|
|
1122
|
+
}
|
|
1123
|
+
if (typeof claims.iat !== "number") {
|
|
1124
|
+
throw idTokenAuthError("token_expired", "iat claim is missing or not a number");
|
|
1125
|
+
}
|
|
1126
|
+
if (claims.iat - skew > nowSec) {
|
|
1127
|
+
throw idTokenAuthError("token_expired", "iat is in the future");
|
|
1128
|
+
}
|
|
1129
|
+
if (typeof claims.nbf === "number" && claims.nbf - skew > nowSec) {
|
|
1130
|
+
throw idTokenAuthError("token_expired", "nbf is in the future");
|
|
1131
|
+
}
|
|
1132
|
+
if (expectations.nonce !== void 0) {
|
|
1133
|
+
if (typeof claims.nonce !== "string" || !constantTimeEquals(claims.nonce, expectations.nonce)) {
|
|
1134
|
+
throw idTokenAuthError("nonce_mismatch", "nonce claim is absent or does not match the request nonce");
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return claims;
|
|
1138
|
+
}
|
|
1007
1139
|
|
|
1008
1140
|
// src/node/jwks.ts
|
|
1009
1141
|
var JWKS_PATH = "/oauth2/jwks";
|
|
1010
1142
|
var COOLDOWN_DURATION_MS = 6e4;
|
|
1011
1143
|
var TIMEOUT_DURATION_MS = 5e3;
|
|
1012
1144
|
function createVerifier(baseUrl) {
|
|
1145
|
+
return createJwksVerifier(`${baseUrl}${JWKS_PATH}`);
|
|
1146
|
+
}
|
|
1147
|
+
function createJwksVerifier(jwksUri) {
|
|
1013
1148
|
let jwksPromise = null;
|
|
1014
1149
|
async function getJwks() {
|
|
1015
1150
|
if (!jwksPromise) {
|
|
1016
1151
|
jwksPromise = import('jose').then(
|
|
1017
|
-
({ createRemoteJWKSet }) => createRemoteJWKSet(new URL(
|
|
1152
|
+
({ createRemoteJWKSet }) => createRemoteJWKSet(new URL(jwksUri), {
|
|
1018
1153
|
cooldownDuration: COOLDOWN_DURATION_MS,
|
|
1019
1154
|
timeoutDuration: TIMEOUT_DURATION_MS
|
|
1020
1155
|
})
|
|
@@ -1028,9 +1163,48 @@ function createVerifier(baseUrl) {
|
|
|
1028
1163
|
const jwks = await getJwks();
|
|
1029
1164
|
const { payload } = await jwtVerify(token, jwks, { algorithms: ["EdDSA"] });
|
|
1030
1165
|
return payload;
|
|
1166
|
+
},
|
|
1167
|
+
async verifyIdToken(token, expectations) {
|
|
1168
|
+
const { decodeProtectedHeader, jwtVerify } = await import('jose');
|
|
1169
|
+
let header;
|
|
1170
|
+
try {
|
|
1171
|
+
header = decodeProtectedHeader(token);
|
|
1172
|
+
} catch {
|
|
1173
|
+
throw idTokenAuthError("invalid_alg", "token is not a well-formed JWS");
|
|
1174
|
+
}
|
|
1175
|
+
assertIdTokenAlg(header.alg);
|
|
1176
|
+
if (!header.kid) {
|
|
1177
|
+
throw idTokenAuthError("unknown_kid", "token carries no kid header");
|
|
1178
|
+
}
|
|
1179
|
+
const jwks = await getJwks();
|
|
1180
|
+
const skew = resolveClockSkewSec(expectations.clockSkewSec);
|
|
1181
|
+
let claims;
|
|
1182
|
+
try {
|
|
1183
|
+
const { payload } = await jwtVerify(token, jwks, {
|
|
1184
|
+
algorithms: [ID_TOKEN_ALG],
|
|
1185
|
+
clockTolerance: skew
|
|
1186
|
+
});
|
|
1187
|
+
claims = payload;
|
|
1188
|
+
} catch (err) {
|
|
1189
|
+
throw mapJoseVerifyError(err);
|
|
1190
|
+
}
|
|
1191
|
+
return checkIdTokenClaims(claims, { ...expectations, clockSkewSec: skew });
|
|
1031
1192
|
}
|
|
1032
1193
|
};
|
|
1033
1194
|
}
|
|
1195
|
+
function mapJoseVerifyError(err) {
|
|
1196
|
+
const code = typeof err === "object" && err !== null && "code" in err ? String(err.code) : "";
|
|
1197
|
+
switch (code) {
|
|
1198
|
+
case "ERR_JWKS_NO_MATCHING_KEY":
|
|
1199
|
+
return idTokenAuthError("unknown_kid", "no JWKS key matches the token kid");
|
|
1200
|
+
case "ERR_JWT_EXPIRED":
|
|
1201
|
+
return idTokenAuthError("token_expired", "exp is in the past");
|
|
1202
|
+
case "ERR_JWT_CLAIM_VALIDATION_FAILED":
|
|
1203
|
+
return idTokenAuthError("token_expired", "a time-based claim (nbf/iat) is not yet valid");
|
|
1204
|
+
default:
|
|
1205
|
+
return idTokenAuthError("invalid_signature", "signature verification failed");
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1034
1208
|
|
|
1035
1209
|
// src/node/session.ts
|
|
1036
1210
|
var NodeSession = class extends SharedSession {
|