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.js
CHANGED
|
@@ -4,6 +4,7 @@ var grpc2 = require('@grpc/grpc-js');
|
|
|
4
4
|
var axios = require('axios');
|
|
5
5
|
var toughCookie = require('tough-cookie');
|
|
6
6
|
var axiosCookiejarSupport = require('axios-cookiejar-support');
|
|
7
|
+
var crypto = require('crypto');
|
|
7
8
|
|
|
8
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
|
|
@@ -57,14 +58,40 @@ var AxiamError = class extends Error {
|
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
var AuthError = class _AuthError extends AxiamError {
|
|
60
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Optional stable, machine-readable reason code for the failure.
|
|
63
|
+
*
|
|
64
|
+
* Populated by the CONTRACT.md §12.4 ID-token validation checklist with
|
|
65
|
+
* one of the seven codes §12.3 rule 3 enumerates (see
|
|
66
|
+
* {@link IdTokenFailureReason}); `undefined` for every other `AuthError`.
|
|
67
|
+
* It is a *code*, never free text, so callers can branch on it without
|
|
68
|
+
* parsing `message`.
|
|
69
|
+
*/
|
|
70
|
+
reason;
|
|
71
|
+
constructor(message, reason) {
|
|
61
72
|
super(message);
|
|
62
73
|
this.name = "AuthError";
|
|
74
|
+
this.reason = reason;
|
|
63
75
|
Object.setPrototypeOf(this, _AuthError.prototype);
|
|
64
76
|
}
|
|
65
77
|
};
|
|
78
|
+
var OAuthProtocolError = class _OAuthProtocolError extends AuthError {
|
|
79
|
+
/** The RFC 6749 `error` code (e.g. `"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`). */
|
|
80
|
+
error;
|
|
81
|
+
/** The server's human-readable `error_description`. Never contains token material. */
|
|
82
|
+
errorDescription;
|
|
83
|
+
constructor(error, errorDescription) {
|
|
84
|
+
super(`${error}: ${errorDescription}`);
|
|
85
|
+
this.name = "OAuthProtocolError";
|
|
86
|
+
this.error = error;
|
|
87
|
+
this.errorDescription = errorDescription;
|
|
88
|
+
Object.setPrototypeOf(this, _OAuthProtocolError.prototype);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
66
91
|
var AuthzError = class _AuthzError extends AxiamError {
|
|
92
|
+
/** The denied action, when the server reported it. */
|
|
67
93
|
action;
|
|
94
|
+
/** The resource the denied action targeted, when the server reported it. */
|
|
68
95
|
resourceId;
|
|
69
96
|
constructor(message, action, resourceId) {
|
|
70
97
|
super(message);
|
|
@@ -75,6 +102,7 @@ var AuthzError = class _AuthzError extends AxiamError {
|
|
|
75
102
|
}
|
|
76
103
|
};
|
|
77
104
|
var NetworkError = class _NetworkError extends AxiamError {
|
|
105
|
+
/** The underlying transport error, with every non-allowlisted response header redacted (§2, X-3). */
|
|
78
106
|
cause;
|
|
79
107
|
constructor(message, cause) {
|
|
80
108
|
super(message);
|
|
@@ -98,6 +126,24 @@ function extractAuthzFieldsFromBody(body) {
|
|
|
98
126
|
const resourceId = typeof record.resource_id === "string" ? record.resource_id : void 0;
|
|
99
127
|
return { action, resourceId };
|
|
100
128
|
}
|
|
129
|
+
var OAUTH2_PATH_PREFIX = "/oauth2/";
|
|
130
|
+
function isOAuth2EndpointUrl(url) {
|
|
131
|
+
if (!url) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return new URL(url).pathname.startsWith(OAUTH2_PATH_PREFIX);
|
|
136
|
+
} catch {
|
|
137
|
+
return url.startsWith(OAUTH2_PATH_PREFIX) || url.includes(OAUTH2_PATH_PREFIX);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function isOAuth2ErrorBody(body) {
|
|
141
|
+
if (body === null || typeof body !== "object") {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const record = body;
|
|
145
|
+
return typeof record.error === "string" && typeof record.error_description === "string";
|
|
146
|
+
}
|
|
101
147
|
var SAFE_RESPONSE_HEADERS = /* @__PURE__ */ new Set([
|
|
102
148
|
"content-type",
|
|
103
149
|
"content-length",
|
|
@@ -135,6 +181,9 @@ function sanitizeAxiosError(err) {
|
|
|
135
181
|
};
|
|
136
182
|
}
|
|
137
183
|
function mapHttpStatusToError(status, message, ctx) {
|
|
184
|
+
if ((status === 400 || status === 401) && isOAuth2EndpointUrl(ctx?.url) && isOAuth2ErrorBody(ctx?.body)) {
|
|
185
|
+
return new OAuthProtocolError(ctx.body.error, ctx.body.error_description);
|
|
186
|
+
}
|
|
138
187
|
if (status === 401) {
|
|
139
188
|
return new AuthError(message);
|
|
140
189
|
}
|
|
@@ -159,6 +208,7 @@ var REDACTED = "[SENSITIVE]";
|
|
|
159
208
|
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
160
209
|
var Sensitive = class {
|
|
161
210
|
#value;
|
|
211
|
+
/** Wrap `value` so it can never be logged or serialized by accident. */
|
|
162
212
|
constructor(value) {
|
|
163
213
|
this.#value = value;
|
|
164
214
|
}
|
|
@@ -166,12 +216,15 @@ var Sensitive = class {
|
|
|
166
216
|
expose() {
|
|
167
217
|
return this.#value;
|
|
168
218
|
}
|
|
219
|
+
/** Returns the `"[SENSITIVE]"` placeholder — never the wrapped value. */
|
|
169
220
|
toString() {
|
|
170
221
|
return REDACTED;
|
|
171
222
|
}
|
|
223
|
+
/** Makes `JSON.stringify()` emit the `"[SENSITIVE]"` placeholder. */
|
|
172
224
|
toJSON() {
|
|
173
225
|
return REDACTED;
|
|
174
226
|
}
|
|
227
|
+
/** Makes `console.log`/`util.inspect` print the `"[SENSITIVE]"` placeholder. */
|
|
175
228
|
[NODE_INSPECT_CUSTOM]() {
|
|
176
229
|
return REDACTED;
|
|
177
230
|
}
|
|
@@ -647,7 +700,14 @@ function createSession(options) {
|
|
|
647
700
|
}
|
|
648
701
|
|
|
649
702
|
// src/rest/interceptors.ts
|
|
650
|
-
var SKIP_REFRESH = [
|
|
703
|
+
var SKIP_REFRESH = [
|
|
704
|
+
"/api/v1/auth/refresh",
|
|
705
|
+
"/api/v1/auth/login",
|
|
706
|
+
"/api/v1/auth/logout",
|
|
707
|
+
"/oauth2/token",
|
|
708
|
+
"/oauth2/introspect",
|
|
709
|
+
"/oauth2/revoke"
|
|
710
|
+
];
|
|
651
711
|
function installCsrfInterceptor(axiosInstance, session) {
|
|
652
712
|
axiosInstance.interceptors.request.use((config) => {
|
|
653
713
|
if (session.isForeignHost(config.url)) {
|
|
@@ -679,6 +739,7 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
679
739
|
try {
|
|
680
740
|
await session.refreshGuard(async () => {
|
|
681
741
|
await session.axios.post("/api/v1/auth/refresh", session.buildRefreshBody());
|
|
742
|
+
await session.onAuthenticated?.();
|
|
682
743
|
});
|
|
683
744
|
return axiosInstance(originalRequest);
|
|
684
745
|
} catch (refreshError) {
|
|
@@ -692,7 +753,13 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
692
753
|
}
|
|
693
754
|
}
|
|
694
755
|
if (status === 401 && isSkipRefresh) {
|
|
695
|
-
return Promise.reject(
|
|
756
|
+
return Promise.reject(
|
|
757
|
+
mapHttpStatusToError(401, "authentication failed", {
|
|
758
|
+
url,
|
|
759
|
+
body: error.response.data,
|
|
760
|
+
cause: error
|
|
761
|
+
})
|
|
762
|
+
);
|
|
696
763
|
}
|
|
697
764
|
return Promise.reject(error);
|
|
698
765
|
}
|
|
@@ -772,6 +839,7 @@ async function verifyMfa(client, mfaToken, code) {
|
|
|
772
839
|
async function refresh(client) {
|
|
773
840
|
try {
|
|
774
841
|
await client.session.axios.post(REFRESH_PATH, client.session.buildRefreshBody());
|
|
842
|
+
await client.session.onAuthenticated?.();
|
|
775
843
|
} catch (err) {
|
|
776
844
|
const status = extractAxiosStatus(err);
|
|
777
845
|
if (status !== void 0) {
|
|
@@ -1029,17 +1097,84 @@ function decodeJwtPayload(token) {
|
|
|
1029
1097
|
return {};
|
|
1030
1098
|
}
|
|
1031
1099
|
}
|
|
1100
|
+
var MAX_CLOCK_SKEW_SEC = 60;
|
|
1101
|
+
function idTokenAuthError(reason, message) {
|
|
1102
|
+
return new AuthError(`id_token validation failed (${reason}): ${message}`, reason);
|
|
1103
|
+
}
|
|
1104
|
+
function resolveClockSkewSec(clockSkewSec) {
|
|
1105
|
+
if (clockSkewSec === void 0) {
|
|
1106
|
+
return MAX_CLOCK_SKEW_SEC;
|
|
1107
|
+
}
|
|
1108
|
+
return Math.min(Math.max(clockSkewSec, 0), MAX_CLOCK_SKEW_SEC);
|
|
1109
|
+
}
|
|
1110
|
+
function constantTimeEquals(a, b) {
|
|
1111
|
+
const left = Buffer.from(a, "utf8");
|
|
1112
|
+
const right = Buffer.from(b, "utf8");
|
|
1113
|
+
if (left.length !== right.length) {
|
|
1114
|
+
return false;
|
|
1115
|
+
}
|
|
1116
|
+
return crypto.timingSafeEqual(left, right);
|
|
1117
|
+
}
|
|
1118
|
+
var ID_TOKEN_ALG = "EdDSA";
|
|
1119
|
+
function assertIdTokenAlg(alg) {
|
|
1120
|
+
if (alg !== ID_TOKEN_ALG) {
|
|
1121
|
+
throw idTokenAuthError(
|
|
1122
|
+
"invalid_alg",
|
|
1123
|
+
`expected alg "${ID_TOKEN_ALG}", got ${typeof alg === "string" ? `"${alg}"` : "no alg header"}`
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function checkIdTokenClaims(claims, expectations, nowSec = Math.floor(Date.now() / 1e3)) {
|
|
1128
|
+
const skew = resolveClockSkewSec(expectations.clockSkewSec);
|
|
1129
|
+
if (claims.iss !== expectations.issuer) {
|
|
1130
|
+
throw idTokenAuthError("invalid_issuer", "iss does not equal the discovery document issuer");
|
|
1131
|
+
}
|
|
1132
|
+
const audiences = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
|
|
1133
|
+
if (!audiences.includes(expectations.clientId)) {
|
|
1134
|
+
throw idTokenAuthError("invalid_audience", "aud does not contain this client_id");
|
|
1135
|
+
}
|
|
1136
|
+
if (audiences.length > 1 && claims.azp !== expectations.clientId) {
|
|
1137
|
+
throw idTokenAuthError(
|
|
1138
|
+
"invalid_audience",
|
|
1139
|
+
"aud holds multiple audiences and azp is absent or does not equal this client_id"
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
if (typeof claims.exp !== "number") {
|
|
1143
|
+
throw idTokenAuthError("token_expired", "exp claim is missing or not a number");
|
|
1144
|
+
}
|
|
1145
|
+
if (claims.exp + skew <= nowSec) {
|
|
1146
|
+
throw idTokenAuthError("token_expired", "exp is in the past");
|
|
1147
|
+
}
|
|
1148
|
+
if (typeof claims.iat !== "number") {
|
|
1149
|
+
throw idTokenAuthError("token_expired", "iat claim is missing or not a number");
|
|
1150
|
+
}
|
|
1151
|
+
if (claims.iat - skew > nowSec) {
|
|
1152
|
+
throw idTokenAuthError("token_expired", "iat is in the future");
|
|
1153
|
+
}
|
|
1154
|
+
if (typeof claims.nbf === "number" && claims.nbf - skew > nowSec) {
|
|
1155
|
+
throw idTokenAuthError("token_expired", "nbf is in the future");
|
|
1156
|
+
}
|
|
1157
|
+
if (expectations.nonce !== void 0) {
|
|
1158
|
+
if (typeof claims.nonce !== "string" || !constantTimeEquals(claims.nonce, expectations.nonce)) {
|
|
1159
|
+
throw idTokenAuthError("nonce_mismatch", "nonce claim is absent or does not match the request nonce");
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return claims;
|
|
1163
|
+
}
|
|
1032
1164
|
|
|
1033
1165
|
// src/node/jwks.ts
|
|
1034
1166
|
var JWKS_PATH = "/oauth2/jwks";
|
|
1035
1167
|
var COOLDOWN_DURATION_MS = 6e4;
|
|
1036
1168
|
var TIMEOUT_DURATION_MS = 5e3;
|
|
1037
1169
|
function createVerifier(baseUrl) {
|
|
1170
|
+
return createJwksVerifier(`${baseUrl}${JWKS_PATH}`);
|
|
1171
|
+
}
|
|
1172
|
+
function createJwksVerifier(jwksUri) {
|
|
1038
1173
|
let jwksPromise = null;
|
|
1039
1174
|
async function getJwks() {
|
|
1040
1175
|
if (!jwksPromise) {
|
|
1041
1176
|
jwksPromise = import('jose').then(
|
|
1042
|
-
({ createRemoteJWKSet }) => createRemoteJWKSet(new URL(
|
|
1177
|
+
({ createRemoteJWKSet }) => createRemoteJWKSet(new URL(jwksUri), {
|
|
1043
1178
|
cooldownDuration: COOLDOWN_DURATION_MS,
|
|
1044
1179
|
timeoutDuration: TIMEOUT_DURATION_MS
|
|
1045
1180
|
})
|
|
@@ -1053,9 +1188,48 @@ function createVerifier(baseUrl) {
|
|
|
1053
1188
|
const jwks = await getJwks();
|
|
1054
1189
|
const { payload } = await jwtVerify(token, jwks, { algorithms: ["EdDSA"] });
|
|
1055
1190
|
return payload;
|
|
1191
|
+
},
|
|
1192
|
+
async verifyIdToken(token, expectations) {
|
|
1193
|
+
const { decodeProtectedHeader, jwtVerify } = await import('jose');
|
|
1194
|
+
let header;
|
|
1195
|
+
try {
|
|
1196
|
+
header = decodeProtectedHeader(token);
|
|
1197
|
+
} catch {
|
|
1198
|
+
throw idTokenAuthError("invalid_alg", "token is not a well-formed JWS");
|
|
1199
|
+
}
|
|
1200
|
+
assertIdTokenAlg(header.alg);
|
|
1201
|
+
if (!header.kid) {
|
|
1202
|
+
throw idTokenAuthError("unknown_kid", "token carries no kid header");
|
|
1203
|
+
}
|
|
1204
|
+
const jwks = await getJwks();
|
|
1205
|
+
const skew = resolveClockSkewSec(expectations.clockSkewSec);
|
|
1206
|
+
let claims;
|
|
1207
|
+
try {
|
|
1208
|
+
const { payload } = await jwtVerify(token, jwks, {
|
|
1209
|
+
algorithms: [ID_TOKEN_ALG],
|
|
1210
|
+
clockTolerance: skew
|
|
1211
|
+
});
|
|
1212
|
+
claims = payload;
|
|
1213
|
+
} catch (err) {
|
|
1214
|
+
throw mapJoseVerifyError(err);
|
|
1215
|
+
}
|
|
1216
|
+
return checkIdTokenClaims(claims, { ...expectations, clockSkewSec: skew });
|
|
1056
1217
|
}
|
|
1057
1218
|
};
|
|
1058
1219
|
}
|
|
1220
|
+
function mapJoseVerifyError(err) {
|
|
1221
|
+
const code = typeof err === "object" && err !== null && "code" in err ? String(err.code) : "";
|
|
1222
|
+
switch (code) {
|
|
1223
|
+
case "ERR_JWKS_NO_MATCHING_KEY":
|
|
1224
|
+
return idTokenAuthError("unknown_kid", "no JWKS key matches the token kid");
|
|
1225
|
+
case "ERR_JWT_EXPIRED":
|
|
1226
|
+
return idTokenAuthError("token_expired", "exp is in the past");
|
|
1227
|
+
case "ERR_JWT_CLAIM_VALIDATION_FAILED":
|
|
1228
|
+
return idTokenAuthError("token_expired", "a time-based claim (nbf/iat) is not yet valid");
|
|
1229
|
+
default:
|
|
1230
|
+
return idTokenAuthError("invalid_signature", "signature verification failed");
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1059
1233
|
|
|
1060
1234
|
// src/node/session.ts
|
|
1061
1235
|
var NodeSession = class extends SharedSession {
|