@canton-network/core-wallet-auth 1.7.0 → 1.9.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/dist/index.cjs +330 -323
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +329 -321
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,347 +1,355 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { providerErrors } from
|
|
3
|
-
import { z } from
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
1
|
+
import { SignJWT, decodeJwt } from "jose";
|
|
2
|
+
import { providerErrors } from "@canton-network/core-rpc-errors";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/auth-utils.ts
|
|
8
5
|
function assertConnected(authContext) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
message: "User is not connected"
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return authContext;
|
|
6
|
+
if (!authContext) throw providerErrors.unauthorized({ message: "User is not connected" });
|
|
7
|
+
return authContext;
|
|
15
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Extract a User ID from the `sub` claim of a JWT. Throws if `sub` is missing.
|
|
11
|
+
*
|
|
12
|
+
* @param token a base64 encoded JWT token
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
16
15
|
function jwtUserId(token) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return sub;
|
|
16
|
+
const { sub } = decodeJwt(token);
|
|
17
|
+
if (!sub) throw new Error("token did not contain a subject field");
|
|
18
|
+
return sub;
|
|
22
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Extract the optional `email` claim from a JWT.
|
|
22
|
+
*
|
|
23
|
+
* @param token a base64 encoded JWT token
|
|
24
|
+
* @returns email when present, otherwise undefined
|
|
25
|
+
*/
|
|
23
26
|
function jwtUserEmail(token) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
return email;
|
|
27
|
+
const { email } = decodeJwt(token);
|
|
28
|
+
if (typeof email !== "string" || email.length === 0) return;
|
|
29
|
+
return email;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetches user claims from the OIDC UserInfo endpoint.
|
|
33
|
+
* Discovers the endpoint via the OIDC discovery document at configUrl.
|
|
34
|
+
*
|
|
35
|
+
* @param configUrl - The OIDC discovery document URL (/.well-known/openid-configuration)
|
|
36
|
+
* @param accessToken - The user's bearer access token
|
|
37
|
+
* @returns The UserInfo claims, or undefined if the IDP does not expose a userinfo endpoint
|
|
38
|
+
* @throws If any network request fails
|
|
39
|
+
*/
|
|
30
40
|
async function fetchOidcUserInfo(configUrl, accessToken) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!config.userinfo_endpoint) {
|
|
39
|
-
return void 0;
|
|
40
|
-
}
|
|
41
|
-
const userInfoResponse = await fetch(config.userinfo_endpoint, {
|
|
42
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
43
|
-
});
|
|
44
|
-
if (!userInfoResponse.ok) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Failed to fetch OIDC userinfo: ${userInfoResponse.status} ${userInfoResponse.statusText}`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return await userInfoResponse.json();
|
|
41
|
+
const configResponse = await fetch(configUrl);
|
|
42
|
+
if (!configResponse.ok) throw new Error(`Failed to fetch OIDC discovery document: ${configResponse.status} ${configResponse.statusText}`);
|
|
43
|
+
const config = await configResponse.json();
|
|
44
|
+
if (!config.userinfo_endpoint) return;
|
|
45
|
+
const userInfoResponse = await fetch(config.userinfo_endpoint, { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
46
|
+
if (!userInfoResponse.ok) throw new Error(`Failed to fetch OIDC userinfo: ${userInfoResponse.status} ${userInfoResponse.statusText}`);
|
|
47
|
+
return await userInfoResponse.json();
|
|
50
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the user email from the OIDC userinfo endpoint.
|
|
51
|
+
*
|
|
52
|
+
* @param authContext - The authentication context
|
|
53
|
+
* @param idp - The IDP configuration
|
|
54
|
+
* @param logger - The logger
|
|
55
|
+
* @returns The user email, or undefined if the email is not found
|
|
56
|
+
*/
|
|
51
57
|
async function resolveUserEmail(authContext, idp, logger) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
idp.configUrl,
|
|
61
|
-
authContext.accessToken
|
|
62
|
-
);
|
|
63
|
-
return userInfo?.email;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
logger?.warn(error, "Failed to resolve user email from OIDC userinfo");
|
|
66
|
-
return void 0;
|
|
67
|
-
}
|
|
58
|
+
if (authContext.email) return authContext.email;
|
|
59
|
+
try {
|
|
60
|
+
if (idp.type !== "oauth") return;
|
|
61
|
+
return (await fetchOidcUserInfo(idp.configUrl, authContext.accessToken))?.email;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logger?.warn(error, "Failed to resolve user email from OIDC userinfo");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
68
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Determine if a given JWT is still valid based on its expiry time.
|
|
69
|
+
*
|
|
70
|
+
* @param token a base64 encoded JWT token
|
|
71
|
+
* @returns true if the token is expired, false if not
|
|
72
|
+
*/
|
|
69
73
|
function jwtExpired(token) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
try {
|
|
75
|
+
const payload = decodeJwt(token);
|
|
76
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
77
|
+
return typeof payload.exp === "number" && payload.exp <= now;
|
|
78
|
+
} catch {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/client-credentials-service.ts
|
|
80
84
|
var ClientCredentialsService = class {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
async getOIDCConfig(url) {
|
|
143
|
-
const res = await fetch(url);
|
|
144
|
-
if (!res.ok) {
|
|
145
|
-
const text = await res.text();
|
|
146
|
-
this.logger?.error(
|
|
147
|
-
{ status: res.status, statusText: res.statusText, body: text },
|
|
148
|
-
"Failed to fetch OIDC config"
|
|
149
|
-
);
|
|
150
|
-
throw new Error(
|
|
151
|
-
`OIDC config error: ${res.status} ${res.statusText}`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
return res.json();
|
|
155
|
-
}
|
|
85
|
+
constructor(configUrl, logger) {
|
|
86
|
+
this.configUrl = configUrl;
|
|
87
|
+
this.logger = logger;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetches the JWT token (M2M) using client credentials.
|
|
91
|
+
*
|
|
92
|
+
* @returns The JWT access token as a string.
|
|
93
|
+
* @throws If fetching the token fails or the response is invalid.
|
|
94
|
+
*/
|
|
95
|
+
async fetchToken(credentials) {
|
|
96
|
+
try {
|
|
97
|
+
const oidcConfig = await this.getOIDCConfig(this.configUrl);
|
|
98
|
+
this.logger?.debug({ oidcConfig }, "Fetched OIDC config");
|
|
99
|
+
const json = await (await this.fetchTokenEndpoint(oidcConfig.token_endpoint, credentials)).json();
|
|
100
|
+
this.logger?.info({ response: json }, `Fetched admin token for clientId: ${credentials.clientId}`);
|
|
101
|
+
if (!json.access_token) throw new Error("No access_token in token endpoint response");
|
|
102
|
+
return json.access_token;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
this.logger?.error({ err: error }, "Failed to fetch admin token");
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async fetchTokenEndpoint(tokenEndpoint, credentials) {
|
|
109
|
+
const params = new URLSearchParams({
|
|
110
|
+
grant_type: "client_credentials",
|
|
111
|
+
scope: credentials.scope ?? "",
|
|
112
|
+
audience: credentials.audience ?? ""
|
|
113
|
+
});
|
|
114
|
+
const password = toClientPassword(credentials.clientId, credentials.clientSecret);
|
|
115
|
+
const res = await fetch(tokenEndpoint, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
119
|
+
Authorization: `Basic ${password}`
|
|
120
|
+
},
|
|
121
|
+
body: params.toString()
|
|
122
|
+
});
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
this.logger?.error({
|
|
125
|
+
status: res.status,
|
|
126
|
+
statusText: res.statusText
|
|
127
|
+
}, "Token endpoint error");
|
|
128
|
+
throw new Error(`Token endpoint error: ${res.status} ${res.statusText}`);
|
|
129
|
+
}
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
132
|
+
async getOIDCConfig(url) {
|
|
133
|
+
const res = await fetch(url);
|
|
134
|
+
if (!res.ok) {
|
|
135
|
+
const text = await res.text();
|
|
136
|
+
this.logger?.error({
|
|
137
|
+
status: res.status,
|
|
138
|
+
statusText: res.statusText,
|
|
139
|
+
body: text
|
|
140
|
+
}, "Failed to fetch OIDC config");
|
|
141
|
+
throw new Error(`OIDC config error: ${res.status} ${res.statusText}`);
|
|
142
|
+
}
|
|
143
|
+
return res.json();
|
|
144
|
+
}
|
|
156
145
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
const toClientPassword = (clientId, clientSecret) => {
|
|
147
|
+
const credentials = `${clientId}:${clientSecret}`;
|
|
148
|
+
return btoa(credentials);
|
|
160
149
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
150
|
+
const clientCredentialsService = (configUrl, logger) => ({ fetchToken: async (credentials) => new ClientCredentialsService(configUrl, logger).fetchToken(credentials) });
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/self-signed-token-service.ts
|
|
164
153
|
var SelfSignedTokenService = class {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
154
|
+
static async fetchToken(logger, credentials, issuer, expirySeconds = 3600) {
|
|
155
|
+
const secret = new TextEncoder().encode(credentials.clientSecret);
|
|
156
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
157
|
+
const jwt = await new SignJWT({
|
|
158
|
+
sub: credentials.clientId,
|
|
159
|
+
aud: credentials.audience || "",
|
|
160
|
+
scope: credentials.scope || "",
|
|
161
|
+
iat: now,
|
|
162
|
+
exp: now + expirySeconds,
|
|
163
|
+
iss: issuer
|
|
164
|
+
}).setProtectedHeader({ alg: "HS256" }).sign(secret);
|
|
165
|
+
logger.info(`Generated self-signed JWT token: ${jwt}`);
|
|
166
|
+
return jwt;
|
|
167
|
+
}
|
|
179
168
|
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
|
|
171
|
+
function _typeof(o) {
|
|
172
|
+
"@babel/helpers - typeof";
|
|
173
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
174
|
+
return typeof o;
|
|
175
|
+
} : function(o) {
|
|
176
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
177
|
+
}, _typeof(o);
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
|
|
181
|
+
function toPrimitive(t, r) {
|
|
182
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
183
|
+
var e = t[Symbol.toPrimitive];
|
|
184
|
+
if (void 0 !== e) {
|
|
185
|
+
var i = e.call(t, r || "default");
|
|
186
|
+
if ("object" != _typeof(i)) return i;
|
|
187
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
188
|
+
}
|
|
189
|
+
return ("string" === r ? String : Number)(t);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
|
|
193
|
+
function toPropertyKey(t) {
|
|
194
|
+
var i = toPrimitive(t, "string");
|
|
195
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
|
|
199
|
+
function _defineProperty(e, r, t) {
|
|
200
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
201
|
+
value: t,
|
|
202
|
+
enumerable: !0,
|
|
203
|
+
configurable: !0,
|
|
204
|
+
writable: !0
|
|
205
|
+
}) : e[r] = t, e;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/auth-token-provider.ts
|
|
209
|
+
/**
|
|
210
|
+
* AuthTokenProvider provides some common functionality across token providers.
|
|
211
|
+
*
|
|
212
|
+
* 1. Token caching: tokens are cached in-memory, so long as the token lifespan is not expired.
|
|
213
|
+
* 2. Context retrieval: deriving a user context from the stored access token.
|
|
214
|
+
*
|
|
215
|
+
*
|
|
216
|
+
* The following programmatic methods of token fetching are supported:
|
|
217
|
+
*
|
|
218
|
+
* - `static`: a fixed, in-memory token. Only used for compatibility, it will totally break for expired tokens.
|
|
219
|
+
* - `self_signed`: only for development purposes, used for Canton setups that accept HMAC256 self signed tokens.
|
|
220
|
+
* - `client_credentials`: used to programmatically acquire tokens via oauth2, a.k.a "machine-to-machine" tokens.
|
|
221
|
+
*/
|
|
222
|
+
var AuthTokenProvider = class AuthTokenProvider {
|
|
223
|
+
constructor(config, logger) {
|
|
224
|
+
this.config = config;
|
|
225
|
+
this.logger = logger;
|
|
226
|
+
_defineProperty(this, "cachedToken", void 0);
|
|
227
|
+
}
|
|
228
|
+
static fromToken(token, logger) {
|
|
229
|
+
return new AuthTokenProvider({
|
|
230
|
+
method: "static",
|
|
231
|
+
token
|
|
232
|
+
}, logger);
|
|
233
|
+
}
|
|
234
|
+
static fromGatewayConfig(idp, auth, logger) {
|
|
235
|
+
if (auth.method === "self_signed") return new AuthTokenProvider({
|
|
236
|
+
method: auth.method,
|
|
237
|
+
issuer: auth.issuer,
|
|
238
|
+
credentials: {
|
|
239
|
+
clientId: auth.clientId,
|
|
240
|
+
clientSecret: auth.clientSecret,
|
|
241
|
+
scope: auth.scope,
|
|
242
|
+
audience: auth.audience
|
|
243
|
+
}
|
|
244
|
+
}, logger);
|
|
245
|
+
if (auth.method === "client_credentials") if (idp.type === "oauth") return new AuthTokenProvider({
|
|
246
|
+
method: auth.method,
|
|
247
|
+
configUrl: idp.configUrl,
|
|
248
|
+
credentials: {
|
|
249
|
+
clientId: auth.clientId,
|
|
250
|
+
clientSecret: auth.clientSecret,
|
|
251
|
+
scope: auth.scope,
|
|
252
|
+
audience: auth.audience
|
|
253
|
+
}
|
|
254
|
+
}, logger);
|
|
255
|
+
else throw new Error(`IDP type ${idp.type} not supported for client_credentials auth`);
|
|
256
|
+
throw new Error(`Auth method ${auth.method} not supported for programmatic access token`);
|
|
257
|
+
}
|
|
258
|
+
async _fetchToken() {
|
|
259
|
+
this.logger.debug("Fetching user auth token");
|
|
260
|
+
switch (this.config.method) {
|
|
261
|
+
case "static": return this.config.token;
|
|
262
|
+
case "self_signed": return SelfSignedTokenService.fetchToken(this.logger, this.config.credentials, this.config.issuer);
|
|
263
|
+
case "client_credentials": return clientCredentialsService(this.config.configUrl, this.logger).fetchToken(this.config.credentials);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
*
|
|
268
|
+
* @returns A valid JWT token retrieved according to the auth configuration given.
|
|
269
|
+
*/
|
|
270
|
+
async getAccessToken() {
|
|
271
|
+
if (this.cachedToken && !jwtExpired(this.cachedToken)) return this.cachedToken;
|
|
272
|
+
else {
|
|
273
|
+
const newToken = await this._fetchToken();
|
|
274
|
+
if (jwtExpired(newToken)) throw new Error("Attempted to refresh a token, but it came back expired.");
|
|
275
|
+
this.cachedToken = newToken;
|
|
276
|
+
return newToken;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
*
|
|
281
|
+
* @returns An AuthContext containing a valid token and userId.
|
|
282
|
+
*/
|
|
283
|
+
async getAuthContext() {
|
|
284
|
+
const accessToken = await this.getAccessToken();
|
|
285
|
+
const userId = jwtUserId(accessToken);
|
|
286
|
+
const email = jwtUserEmail(accessToken);
|
|
287
|
+
return {
|
|
288
|
+
accessToken,
|
|
289
|
+
userId,
|
|
290
|
+
...email ? { email } : {}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
282
293
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/config/schema.ts
|
|
296
|
+
const authorizationCodeAuthSchema = z.object({
|
|
297
|
+
method: z.literal("authorization_code"),
|
|
298
|
+
audience: z.string(),
|
|
299
|
+
scope: z.string(),
|
|
300
|
+
clientId: z.string()
|
|
301
|
+
}).meta({ description: "Authorization code flow authentication configuration. This is used for browser-based application login." });
|
|
302
|
+
const clientCredentialsAuthSchema = z.object({
|
|
303
|
+
method: z.literal("client_credentials"),
|
|
304
|
+
audience: z.string(),
|
|
305
|
+
scope: z.string(),
|
|
306
|
+
clientId: z.string(),
|
|
307
|
+
clientSecret: z.string()
|
|
297
308
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
309
|
+
const selfSignedAuthSchema = z.object({
|
|
310
|
+
method: z.literal("self_signed"),
|
|
311
|
+
issuer: z.string(),
|
|
312
|
+
audience: z.string(),
|
|
313
|
+
scope: z.string(),
|
|
314
|
+
clientId: z.string(),
|
|
315
|
+
clientSecret: z.string()
|
|
305
316
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
317
|
+
const clientCredentialsEnvAuthSchema = z.object({
|
|
318
|
+
method: z.literal("client_credentials"),
|
|
319
|
+
audience: z.string(),
|
|
320
|
+
scope: z.string(),
|
|
321
|
+
clientId: z.string(),
|
|
322
|
+
clientSecretEnv: z.string()
|
|
312
323
|
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
324
|
+
const selfSignedEnvAuthSchema = z.object({
|
|
325
|
+
method: z.literal("self_signed"),
|
|
326
|
+
issuer: z.string(),
|
|
327
|
+
audience: z.string(),
|
|
328
|
+
scope: z.string(),
|
|
329
|
+
clientId: z.string(),
|
|
330
|
+
clientSecretEnv: z.string()
|
|
320
331
|
});
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
332
|
+
const authSchema = z.discriminatedUnion("method", [
|
|
333
|
+
authorizationCodeAuthSchema,
|
|
334
|
+
clientCredentialsAuthSchema,
|
|
335
|
+
selfSignedAuthSchema
|
|
325
336
|
]);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
337
|
+
const authFromEnvSchema = z.discriminatedUnion("method", [
|
|
338
|
+
authorizationCodeAuthSchema,
|
|
339
|
+
clientCredentialsEnvAuthSchema,
|
|
340
|
+
selfSignedEnvAuthSchema
|
|
330
341
|
]);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
})
|
|
343
|
-
]);
|
|
344
|
-
|
|
342
|
+
const idpSchema = z.discriminatedUnion("type", [z.object({
|
|
343
|
+
id: z.string(),
|
|
344
|
+
type: z.literal("self_signed"),
|
|
345
|
+
issuer: z.string()
|
|
346
|
+
}), z.object({
|
|
347
|
+
id: z.string(),
|
|
348
|
+
type: z.literal("oauth"),
|
|
349
|
+
issuer: z.string(),
|
|
350
|
+
configUrl: z.string().url()
|
|
351
|
+
})]);
|
|
352
|
+
//#endregion
|
|
345
353
|
export { AuthTokenProvider, ClientCredentialsService, assertConnected, authFromEnvSchema, authSchema, clientCredentialsService, fetchOidcUserInfo, idpSchema, jwtExpired, jwtUserEmail, jwtUserId, resolveUserEmail };
|
|
346
|
-
|
|
354
|
+
|
|
347
355
|
//# sourceMappingURL=index.js.map
|