@crossauth/frontend 0.0.38 → 0.0.40
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 +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.js +180 -136
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,33 +7,33 @@ var f = (r, e, t) => Oe(r, typeof e != "symbol" ? e + "" : e, t), de = (r, e, t)
|
|
|
7
7
|
var p = (r, e, t) => (de(r, e, "read from private field"), t ? t.call(r) : e.get(r)), E = (r, e, t) => e.has(r) ? ce("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), T = (r, e, t, o) => (de(r, e, "write to private field"), o ? o.call(r, t) : e.set(r, t), t);
|
|
8
8
|
var Ne = Object.defineProperty, ye = (r) => {
|
|
9
9
|
throw TypeError(r);
|
|
10
|
-
}, He = (r, e, t) => e in r ? Ne(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t,
|
|
10
|
+
}, He = (r, e, t) => e in r ? Ne(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e, t) => He(r, typeof e != "symbol" ? e + "" : e, t), we = (r, e, t) => e.has(r) || ye("Cannot " + t), w = (r, e, t) => (we(r, e, "read from private field"), e.get(r)), he = (r, e, t) => e.has(r) ? ye("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), Y = (r, e, t, o) => (we(r, e, "write to private field"), e.set(r, t), t);
|
|
11
11
|
class H {
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
u(H, "active", "active"), /** Deactivated account. User cannot log in */
|
|
14
|
+
u(H, "disabled", "disabled"), /** Two factor authentication has been actived for this user
|
|
15
15
|
* but has not yet been configured. Once a user logs in,
|
|
16
16
|
* they will be directed to a page to configure 2FA and will
|
|
17
17
|
* not be able to do anything else (that requires login) until
|
|
18
18
|
* they have done so.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
u(H, "awaitingTwoFactorSetup", "awaitingtwofactorsetup"), /** Email verification has been turned on but user has not
|
|
21
21
|
* verified his or her email address. Cannot log on until it has
|
|
22
22
|
* been verified.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
u(H, "awaitingEmailVerification", "awaitingemailverification"), /**
|
|
25
25
|
* If the state is set to this, the user may not access any
|
|
26
26
|
* login-required functions unless he or she has changed their password.
|
|
27
27
|
*
|
|
28
28
|
* Upon login, the user is redirected to the change password page.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
u(H, "passwordChangeNeeded", "passwordchangeneeded"), /**
|
|
31
31
|
* If the state is set to this, the user may not access any
|
|
32
32
|
* login-required functions unless he or she has reset their password.
|
|
33
33
|
*
|
|
34
34
|
* Upon login, the user is redirected to the reset password page.
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
u(H, "passwordResetNeeded", "passwordresetneeded"), /**
|
|
37
37
|
* If the state is set to this, the user may not access any
|
|
38
38
|
* login-required functions unless he or she has reset their second
|
|
39
39
|
* factor configuration.
|
|
@@ -44,26 +44,26 @@ l(H, "passwordResetNeeded", "passwordresetneeded"), /**
|
|
|
44
44
|
* this value and the user will then be prompted to configure 2FA
|
|
45
45
|
* upon login.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
u(H, "factor2ResetNeeded", "factor2resetneeded"), /**
|
|
48
48
|
* If the state is set to this, the user may not access any
|
|
49
49
|
* login-required functions unless he or she has reset their password
|
|
50
50
|
* and then resets factor2.
|
|
51
51
|
*
|
|
52
52
|
* Upon login, the user is redirected to the reset password page.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
u(H, "passwordAndFactor2ResetNeeded", "passwordandfactor2resetneeded");
|
|
55
55
|
class R {
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
u(R, "session", "s:"), /** Password Reset Token */
|
|
58
|
+
u(R, "passwordResetToken", "p:"), /** Email verification token */
|
|
59
|
+
u(R, "emailVerificationToken", "e:"), /** API key */
|
|
60
|
+
u(R, "apiKey", "api:"), /** OAuth authorization code */
|
|
61
|
+
u(R, "authorizationCode", "authz:"), /** OAuth access token */
|
|
62
|
+
u(R, "accessToken", "access:"), /** OAuth refresh token */
|
|
63
|
+
u(R, "refreshToken", "refresh:"), /** OAuth MFA key (used by the password MFA flow) */
|
|
64
|
+
u(R, "mfaToken", "omfa:"), /** Device code device code */
|
|
65
|
+
u(R, "deviceCode", "dc:"), /** Device code flow user code */
|
|
66
|
+
u(R, "userCode", "uc:");
|
|
67
67
|
var m = /* @__PURE__ */ ((r) => (r[r.UserNotExist = 0] = "UserNotExist", r[r.PasswordInvalid = 1] = "PasswordInvalid", r[r.EmailNotExist = 2] = "EmailNotExist", r[r.UsernameOrPasswordInvalid = 3] = "UsernameOrPasswordInvalid", r[r.InvalidClientId = 4] = "InvalidClientId", r[r.ClientExists = 5] = "ClientExists", r[r.InvalidClientSecret = 6] = "InvalidClientSecret", r[r.InvalidClientIdOrSecret = 7] = "InvalidClientIdOrSecret", r[r.InvalidRedirectUri = 8] = "InvalidRedirectUri", r[r.InvalidOAuthFlow = 9] = "InvalidOAuthFlow", r[r.UserNotActive = 10] = "UserNotActive", r[r.EmailNotVerified = 11] = "EmailNotVerified", r[r.TwoFactorIncomplete = 12] = "TwoFactorIncomplete", r[r.Unauthorized = 13] = "Unauthorized", r[r.UnauthorizedClient = 14] = "UnauthorizedClient", r[r.InvalidScope = 15] = "InvalidScope", r[r.InsufficientScope = 16] = "InsufficientScope", r[r.InsufficientPriviledges = 17] = "InsufficientPriviledges", r[r.Forbidden = 18] = "Forbidden", r[r.InvalidKey = 19] = "InvalidKey", r[r.InvalidCsrf = 20] = "InvalidCsrf", r[r.InvalidSession = 21] = "InvalidSession", r[r.Expired = 22] = "Expired", r[r.Connection = 23] = "Connection", r[r.InvalidHash = 24] = "InvalidHash", r[r.UnsupportedAlgorithm = 25] = "UnsupportedAlgorithm", r[r.KeyExists = 26] = "KeyExists", r[r.PasswordChangeNeeded = 27] = "PasswordChangeNeeded", r[r.PasswordResetNeeded = 28] = "PasswordResetNeeded", r[r.Factor2ResetNeeded = 29] = "Factor2ResetNeeded", r[r.Configuration = 30] = "Configuration", r[r.InvalidEmail = 31] = "InvalidEmail", r[r.InvalidPhoneNumber = 32] = "InvalidPhoneNumber", r[r.InvalidUsername = 33] = "InvalidUsername", r[r.PasswordMatch = 34] = "PasswordMatch", r[r.InvalidToken = 35] = "InvalidToken", r[r.MfaRequired = 36] = "MfaRequired", r[r.PasswordFormat = 37] = "PasswordFormat", r[r.DataFormat = 38] = "DataFormat", r[r.FetchError = 39] = "FetchError", r[r.UserExists = 40] = "UserExists", r[r.FormEntry = 41] = "FormEntry", r[r.BadRequest = 42] = "BadRequest", r[r.AuthorizationPending = 43] = "AuthorizationPending", r[r.SlowDown = 44] = "SlowDown", r[r.ExpiredToken = 45] = "ExpiredToken", r[r.ConstraintViolation = 46] = "ConstraintViolation", r[r.NotImplemented = 47] = "NotImplemented", r[r.UnknownError = 48] = "UnknownError", r))(m || {});
|
|
68
68
|
class g extends Error {
|
|
69
69
|
/**
|
|
@@ -74,7 +74,7 @@ class g extends Error {
|
|
|
74
74
|
*/
|
|
75
75
|
constructor(e, t = void 0) {
|
|
76
76
|
let o, i = 500;
|
|
77
|
-
e == 0 ? (o = "User does not exist", i = 401) : e == 1 ? (o = "Password doesn't match", i = 401) : e == 3 ? (o = "Username or password incorrect", i = 401) : e == 4 ? (o = "Client id is invalid", i = 401) : e == 5 ? (o = "Client ID or name already exists", i = 500) : e == 6 ? (o = "Client secret is invalid", i = 401) : e == 7 ? (o = "Client id or secret is invalid", i = 401) : e == 8 ? (o = "Redirect Uri is not registered", i = 401) : e == 9 ? (o = "Invalid OAuth flow type", i = 500) : e == 2 ? (o = "No user exists with that email address", i = 401) : e == 10 ? (o = "Account is not active", i = 403) : e == 33 ? (o = "Username is not in an allowed format", i = 400) : e == 31 ? (o = "Email is not in an allowed format", i = 400) : e == 32 ? (o = "Phone number is not in an allowed format", i = 400) : e == 11 ? (o = "Email address has not been verified", i = 403) : e == 12 ? (o = "Two-factor setup is not complete", i = 403) : e == 13 ? (o = "Not authorized", i = 401) : e == 14 ? (o = "Client not authorized", i = 401) : e == 15 ? (o = "Invalid scope", i = 403) : e == 16 ? (o = "Insufficient scope", i = 403) : e == 23 ? o = "Connection failure" : e == 22 ? (o = "Token has expired", i = 401) : e == 24 ? o = "Hash is not in a valid format" : e == 19 ? (o = "Key is invalid", i = 401) : e == 18 ? (o = "You do not have permission to access this resource", i = 403) : e == 17 ? (o = "You do not have the right privileges to access this resource", i = 401) : e == 20 ? (o = "CSRF token is invalid", i = 401) : e == 21 ? (o = "Session cookie is invalid", i = 401) : e == 25 ? o = "Algorithm not supported" : e == 26 ? o = "Attempt to create a key that already exists" : e == 27 ? (o = "User must change password", i = 403) : e == 28 ? (o = "User must reset password", i = 403) : e == 29 ? (o = "User must reset 2FA", i = 403) : e == 30 ? o = "There was an error in the configuration" : e == 34 ? (o = "Passwords do not match", i = 401) : e == 35 ? (o = "Token is not valid", i = 401) : e == 36 ? (o = "MFA is required", i = 401) : e == 37 ? (o = "Password format was incorrect", i = 401) : e == 40 ? (o = "User already exists", i = 400) : e == 42 ? (o = "The request is invalid", i = 400) : e == 38 ? (o = "Session data has unexpected format", i = 500) : e == 39 ? (o = "Couldn't execute a fetch", i = 500) : e == 43 ? (o = "Waiting for authorization", i = 200) : e == 44 ? (o = "Slow polling down by 5 seconds", i = 200) : e == 45 ? (o = "Token has expired", i = 401) : e == 46 ? (o = "Database update/insert caused a constraint violation", i = 500) : e == 47 ? (o = "This method has not been implemented", i = 500) : (o = "Unknown error", i = 500), t != null && !Array.isArray(t) ? o = t : Array.isArray(t) && (o = t.join(". ")), super(o),
|
|
77
|
+
e == 0 ? (o = "User does not exist", i = 401) : e == 1 ? (o = "Password doesn't match", i = 401) : e == 3 ? (o = "Username or password incorrect", i = 401) : e == 4 ? (o = "Client id is invalid", i = 401) : e == 5 ? (o = "Client ID or name already exists", i = 500) : e == 6 ? (o = "Client secret is invalid", i = 401) : e == 7 ? (o = "Client id or secret is invalid", i = 401) : e == 8 ? (o = "Redirect Uri is not registered", i = 401) : e == 9 ? (o = "Invalid OAuth flow type", i = 500) : e == 2 ? (o = "No user exists with that email address", i = 401) : e == 10 ? (o = "Account is not active", i = 403) : e == 33 ? (o = "Username is not in an allowed format", i = 400) : e == 31 ? (o = "Email is not in an allowed format", i = 400) : e == 32 ? (o = "Phone number is not in an allowed format", i = 400) : e == 11 ? (o = "Email address has not been verified", i = 403) : e == 12 ? (o = "Two-factor setup is not complete", i = 403) : e == 13 ? (o = "Not authorized", i = 401) : e == 14 ? (o = "Client not authorized", i = 401) : e == 15 ? (o = "Invalid scope", i = 403) : e == 16 ? (o = "Insufficient scope", i = 403) : e == 23 ? o = "Connection failure" : e == 22 ? (o = "Token has expired", i = 401) : e == 24 ? o = "Hash is not in a valid format" : e == 19 ? (o = "Key is invalid", i = 401) : e == 18 ? (o = "You do not have permission to access this resource", i = 403) : e == 17 ? (o = "You do not have the right privileges to access this resource", i = 401) : e == 20 ? (o = "CSRF token is invalid", i = 401) : e == 21 ? (o = "Session cookie is invalid", i = 401) : e == 25 ? o = "Algorithm not supported" : e == 26 ? o = "Attempt to create a key that already exists" : e == 27 ? (o = "User must change password", i = 403) : e == 28 ? (o = "User must reset password", i = 403) : e == 29 ? (o = "User must reset 2FA", i = 403) : e == 30 ? o = "There was an error in the configuration" : e == 34 ? (o = "Passwords do not match", i = 401) : e == 35 ? (o = "Token is not valid", i = 401) : e == 36 ? (o = "MFA is required", i = 401) : e == 37 ? (o = "Password format was incorrect", i = 401) : e == 40 ? (o = "User already exists", i = 400) : e == 42 ? (o = "The request is invalid", i = 400) : e == 38 ? (o = "Session data has unexpected format", i = 500) : e == 39 ? (o = "Couldn't execute a fetch", i = 500) : e == 43 ? (o = "Waiting for authorization", i = 200) : e == 44 ? (o = "Slow polling down by 5 seconds", i = 200) : e == 45 ? (o = "Token has expired", i = 401) : e == 46 ? (o = "Database update/insert caused a constraint violation", i = 500) : e == 47 ? (o = "This method has not been implemented", i = 500) : (o = "Unknown error", i = 500), t != null && !Array.isArray(t) ? o = t : Array.isArray(t) && (o = t.join(". ")), super(o), u(this, "isCrossauthError", !0), u(this, "httpStatus"), u(this, "code"), u(this, "codeName"), u(this, "messages"), this.code = e, this.codeName = m[e], this.httpStatus = i, this.name = "CrossauthError", Array.isArray(t) ? this.messages = t : this.messages = [o], Object.setPrototypeOf(this, g.prototype);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* OAuth defines certain error types. To convert the error in an OAuth
|
|
@@ -195,7 +195,7 @@ const W = class P {
|
|
|
195
195
|
* @param level the level to report to
|
|
196
196
|
*/
|
|
197
197
|
constructor(e) {
|
|
198
|
-
if (
|
|
198
|
+
if (u(this, "level"), e) this.level = e;
|
|
199
199
|
else if (typeof process < "u" && "CROSSAUTH_LOG_LEVEL" in process.env) {
|
|
200
200
|
const t = (process.env.CROSSAUTH_LOG_LEVEL ?? "ERROR").toUpperCase();
|
|
201
201
|
P.levelName.includes(t) ? this.level = P.levelName.indexOf(t) : this.level = P.Error;
|
|
@@ -257,11 +257,11 @@ const W = class P {
|
|
|
257
257
|
globalThis.crossauthLogger = e, globalThis.crossauthLoggerAcceptsJson = t;
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
u(W, "None", 0), /** Only log errors */
|
|
261
|
+
u(W, "Error", 1), /** Log errors and warning */
|
|
262
|
+
u(W, "Warn", 2), /** Log errors, warnings and info messages */
|
|
263
|
+
u(W, "Info", 3), /** Log everything */
|
|
264
|
+
u(W, "Debug", 4), u(W, "levelName", ["NONE", "ERROR", "WARN", "INFO", "DEBUG"]);
|
|
265
265
|
let d = W;
|
|
266
266
|
function h(r) {
|
|
267
267
|
let e;
|
|
@@ -627,7 +627,7 @@ const be = (r) => (r == null ? void 0 : r[Symbol.toStringTag]) === "KeyObject",
|
|
|
627
627
|
}
|
|
628
628
|
}, Ee = async (r, e, t, o, i) => {
|
|
629
629
|
let n, s;
|
|
630
|
-
const a = new Uint8Array(atob(t.replace(r, "")).split("").map((
|
|
630
|
+
const a = new Uint8Array(atob(t.replace(r, "")).split("").map((l) => l.charCodeAt(0))), c = e === "spki";
|
|
631
631
|
switch (o) {
|
|
632
632
|
case "PS256":
|
|
633
633
|
case "PS384":
|
|
@@ -661,8 +661,8 @@ const be = (r) => (r == null ? void 0 : r[Symbol.toStringTag]) === "KeyObject",
|
|
|
661
661
|
case "ECDH-ES+A128KW":
|
|
662
662
|
case "ECDH-ES+A192KW":
|
|
663
663
|
case "ECDH-ES+A256KW": {
|
|
664
|
-
const
|
|
665
|
-
n =
|
|
664
|
+
const l = ue(a);
|
|
665
|
+
n = l.startsWith("P-") ? { name: "ECDH", namedCurve: l } : { name: l }, s = c ? [] : ["deriveBits"];
|
|
666
666
|
break;
|
|
667
667
|
}
|
|
668
668
|
case "EdDSA":
|
|
@@ -824,14 +824,14 @@ async function sr(r, e, t) {
|
|
|
824
824
|
throw new S("JWS Payload must be a string or an Uint8Array instance");
|
|
825
825
|
let c = !1;
|
|
826
826
|
typeof e == "function" && (e = await e(o, r), c = !0), er(a, e, "verify");
|
|
827
|
-
const
|
|
827
|
+
const l = je(X.encode(r.protected ?? ""), X.encode("."), typeof r.payload == "string" ? X.encode(r.payload) : r.payload);
|
|
828
828
|
let y;
|
|
829
829
|
try {
|
|
830
830
|
y = F(r.signature);
|
|
831
831
|
} catch {
|
|
832
832
|
throw new S("Failed to base64url decode the signature");
|
|
833
833
|
}
|
|
834
|
-
if (!await ir(a, e, y,
|
|
834
|
+
if (!await ir(a, e, y, l))
|
|
835
835
|
throw new Ke();
|
|
836
836
|
let k;
|
|
837
837
|
if (s)
|
|
@@ -841,8 +841,8 @@ async function sr(r, e, t) {
|
|
|
841
841
|
throw new S("Failed to base64url decode the payload");
|
|
842
842
|
}
|
|
843
843
|
else typeof r.payload == "string" ? k = X.encode(r.payload) : k = r.payload;
|
|
844
|
-
const
|
|
845
|
-
return r.protected !== void 0 && (
|
|
844
|
+
const b = { payload: k };
|
|
845
|
+
return r.protected !== void 0 && (b.protectedHeader = o), r.header !== void 0 && (b.unprotectedHeader = r.header), c ? { ...b, key: e } : b;
|
|
846
846
|
}
|
|
847
847
|
async function nr(r, e, t) {
|
|
848
848
|
if (r instanceof Uint8Array && (r = G.decode(r)), typeof r != "string")
|
|
@@ -971,22 +971,22 @@ const C = class v {
|
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
973
|
};
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
974
|
+
u(C, "All", "all"), /** OAuth authorization code flow (without PKCE) */
|
|
975
|
+
u(C, "AuthorizationCode", "authorizationCode"), /** OAuth authorization code flow with PKCE */
|
|
976
|
+
u(C, "AuthorizationCodeWithPKCE", "authorizationCodeWithPKCE"), /** Auth client credentials flow */
|
|
977
|
+
u(C, "ClientCredentials", "clientCredentials"), /** OAuth refresh token flow */
|
|
978
|
+
u(C, "RefreshToken", "refreshToken"), /** OAuth device code flow */
|
|
979
|
+
u(C, "DeviceCode", "deviceCode"), /** OAuth password flow */
|
|
980
|
+
u(C, "Password", "password"), /** The Auth0 password MFA extension to the password flow */
|
|
981
|
+
u(C, "PasswordMfa", "passwordMfa"), /** The OpenID Connect authorization code flow, with or without
|
|
982
982
|
* PKCE.
|
|
983
983
|
*/
|
|
984
|
-
|
|
984
|
+
u(C, "OidcAuthorizationCode", "oidcAuthorizationCode"), /** A user friendly name for the given flow ID
|
|
985
985
|
*
|
|
986
986
|
* For example, if you pass "authorizationCode"
|
|
987
987
|
* (`OAuthFlows.AuthorizationCode`) you will get `"Authorization Code"`.
|
|
988
988
|
*/
|
|
989
|
-
|
|
989
|
+
u(C, "flowName", {
|
|
990
990
|
[C.AuthorizationCode]: "Authorization Code",
|
|
991
991
|
[C.AuthorizationCodeWithPKCE]: "Authorization Code with PKCE",
|
|
992
992
|
[C.ClientCredentials]: "Client Credentials",
|
|
@@ -996,7 +996,7 @@ l(C, "flowName", {
|
|
|
996
996
|
[C.PasswordMfa]: "Password MFA",
|
|
997
997
|
[C.OidcAuthorizationCode]: "OIDC Authorization Code"
|
|
998
998
|
});
|
|
999
|
-
var _,
|
|
999
|
+
var _, A;
|
|
1000
1000
|
class cr {
|
|
1001
1001
|
/**
|
|
1002
1002
|
* Constructor.
|
|
@@ -1034,17 +1034,17 @@ class cr {
|
|
|
1034
1034
|
stateLength: s,
|
|
1035
1035
|
verifierLength: a,
|
|
1036
1036
|
tokenConsumer: c,
|
|
1037
|
-
authServerCredentials:
|
|
1037
|
+
authServerCredentials: l,
|
|
1038
1038
|
authServerMode: y,
|
|
1039
1039
|
authServerHeaders: k
|
|
1040
1040
|
}) {
|
|
1041
|
-
|
|
1041
|
+
u(this, "authServerBaseUrl", ""), he(this, _), he(this, A), u(this, "codeChallengeMethod", "S256"), u(this, "verifierLength", 32), u(this, "redirect_uri"), u(this, "stateLength", 32), u(this, "authzCode", ""), u(this, "oidcConfig"), u(this, "tokenConsumer"), u(this, "authServerHeaders", {}), u(this, "authServerMode"), u(this, "authServerCredentials"), u(this, "oauthPostType", "json"), u(this, "oauthLogFetch", !1), u(this, "oauthUseUserInfoEndpoint", !1), u(this, "oauthAuthorizeRedirect"), this.tokenConsumer = c, this.authServerBaseUrl = e, a && (this.verifierLength = a), s && (this.stateLength = s), t && Y(this, _, t), o && Y(this, A, o), i && (this.redirect_uri = i), n && (this.codeChallengeMethod = n), this.authServerBaseUrl = e, l && (this.authServerCredentials = l), y && (this.authServerMode = y), k && (this.authServerHeaders = k);
|
|
1042
1042
|
}
|
|
1043
1043
|
set client_id(e) {
|
|
1044
1044
|
Y(this, _, e);
|
|
1045
1045
|
}
|
|
1046
1046
|
set client_secret(e) {
|
|
1047
|
-
Y(this,
|
|
1047
|
+
Y(this, A, e);
|
|
1048
1048
|
}
|
|
1049
1049
|
/**
|
|
1050
1050
|
* Loads OpenID Connect configuration so that the client can determine
|
|
@@ -1134,8 +1134,8 @@ class cr {
|
|
|
1134
1134
|
};
|
|
1135
1135
|
let c = this.oidcConfig.authorization_endpoint;
|
|
1136
1136
|
this.oauthAuthorizeRedirect && (c = this.oauthAuthorizeRedirect);
|
|
1137
|
-
let
|
|
1138
|
-
return t && (
|
|
1137
|
+
let l = c + "?response_type=code&client_id=" + encodeURIComponent(w(this, _)) + "&state=" + encodeURIComponent(e) + "&redirect_uri=" + encodeURIComponent(this.redirect_uri);
|
|
1138
|
+
return t && (l += "&scope=" + encodeURIComponent(t)), i && o && (l += "&code_challenge=" + o), { url: l };
|
|
1139
1139
|
}
|
|
1140
1140
|
async codeChallengeAndVerifier() {
|
|
1141
1141
|
const e = this.randomValue(this.verifierLength);
|
|
@@ -1159,6 +1159,16 @@ class cr {
|
|
|
1159
1159
|
return d.logger.debug(h({ err: s })), d.logger.error(h({ msg: "Couldn't get user info", cerr: s })), o = s.oauthErrorCode, i = "Couldn't get user info: " + s.message, { error: o, error_description: i };
|
|
1160
1160
|
}
|
|
1161
1161
|
}
|
|
1162
|
+
async getAccessPayload(e, t) {
|
|
1163
|
+
let o, i;
|
|
1164
|
+
try {
|
|
1165
|
+
let n;
|
|
1166
|
+
return n = await this.validateAccessToken(e, t), n ? { payload: n } : (o = "access_denied", i = "Invalid access token received", { error: o, error_description: i });
|
|
1167
|
+
} catch (n) {
|
|
1168
|
+
const s = g.asCrossauthError(n);
|
|
1169
|
+
return d.logger.debug(h({ err: s })), d.logger.error(h({ msg: "Couldn't get user info", cerr: s })), o = s.oauthErrorCode, i = "Couldn't get user info: " + s.message, { error: o, error_description: i };
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1162
1172
|
/**
|
|
1163
1173
|
* This implements the functionality behind the redirect URI
|
|
1164
1174
|
*
|
|
@@ -1194,26 +1204,26 @@ class cr {
|
|
|
1194
1204
|
error_description: "Cannot get token endpoint"
|
|
1195
1205
|
};
|
|
1196
1206
|
const c = this.oidcConfig.token_endpoint;
|
|
1197
|
-
let
|
|
1198
|
-
|
|
1207
|
+
let l, y;
|
|
1208
|
+
l = "authorization_code", y = w(this, A);
|
|
1199
1209
|
let k = {
|
|
1200
|
-
grant_type:
|
|
1210
|
+
grant_type: l,
|
|
1201
1211
|
client_id: w(this, _),
|
|
1202
1212
|
code: this.authzCode,
|
|
1203
1213
|
redirect_uri: this.redirect_uri
|
|
1204
1214
|
};
|
|
1205
1215
|
t && (k.scope = t), y && (k.client_secret = y), o && (k.code_verifier = o);
|
|
1206
1216
|
try {
|
|
1207
|
-
let
|
|
1208
|
-
if (
|
|
1209
|
-
const L = await this.getIdPayload(
|
|
1217
|
+
let b = await this.post(c, k, this.authServerHeaders);
|
|
1218
|
+
if (b.id_token) {
|
|
1219
|
+
const L = await this.getIdPayload(b.id_token, b.access_token);
|
|
1210
1220
|
if (L.error)
|
|
1211
1221
|
return L;
|
|
1212
|
-
|
|
1222
|
+
b.id_payload = L.payload;
|
|
1213
1223
|
}
|
|
1214
|
-
return
|
|
1215
|
-
} catch (
|
|
1216
|
-
return d.logger.error(h({ err:
|
|
1224
|
+
return b;
|
|
1225
|
+
} catch (b) {
|
|
1226
|
+
return d.logger.error(h({ err: b })), {
|
|
1217
1227
|
error: "server_error",
|
|
1218
1228
|
error_description: "Unable to get access token from server"
|
|
1219
1229
|
};
|
|
@@ -1250,7 +1260,7 @@ class cr {
|
|
|
1250
1260
|
let n = {
|
|
1251
1261
|
grant_type: "client_credentials",
|
|
1252
1262
|
client_id: w(this, _),
|
|
1253
|
-
client_secret: w(this,
|
|
1263
|
+
client_secret: w(this, A)
|
|
1254
1264
|
};
|
|
1255
1265
|
e && (n.scope = e);
|
|
1256
1266
|
try {
|
|
@@ -1300,7 +1310,7 @@ class cr {
|
|
|
1300
1310
|
let a = {
|
|
1301
1311
|
grant_type: "password",
|
|
1302
1312
|
client_id: w(this, _),
|
|
1303
|
-
client_secret: w(this,
|
|
1313
|
+
client_secret: w(this, A),
|
|
1304
1314
|
username: e,
|
|
1305
1315
|
password: t
|
|
1306
1316
|
};
|
|
@@ -1308,10 +1318,10 @@ class cr {
|
|
|
1308
1318
|
try {
|
|
1309
1319
|
let c = await this.post(s, a, this.authServerHeaders);
|
|
1310
1320
|
if (c.id_token) {
|
|
1311
|
-
const
|
|
1312
|
-
if (
|
|
1313
|
-
return
|
|
1314
|
-
c.id_payload =
|
|
1321
|
+
const l = await this.getIdPayload(c.id_token, c.access_token);
|
|
1322
|
+
if (l.error)
|
|
1323
|
+
return l;
|
|
1324
|
+
c.id_payload = l.payload;
|
|
1315
1325
|
}
|
|
1316
1326
|
return c;
|
|
1317
1327
|
} catch (c) {
|
|
@@ -1351,18 +1361,18 @@ class cr {
|
|
|
1351
1361
|
};
|
|
1352
1362
|
let a = [];
|
|
1353
1363
|
for (let c = 0; c < s.length; ++c) {
|
|
1354
|
-
const
|
|
1355
|
-
if (!
|
|
1364
|
+
const l = s[c];
|
|
1365
|
+
if (!l.id || !l.authenticator_type || !l.active)
|
|
1356
1366
|
return {
|
|
1357
1367
|
error: "server_error",
|
|
1358
1368
|
error_description: "Invalid mfa/authenticators response"
|
|
1359
1369
|
};
|
|
1360
1370
|
a.push({
|
|
1361
|
-
id:
|
|
1362
|
-
authenticator_type:
|
|
1363
|
-
active:
|
|
1364
|
-
name:
|
|
1365
|
-
oob_channel:
|
|
1371
|
+
id: l.id,
|
|
1372
|
+
authenticator_type: l.authenticator_type,
|
|
1373
|
+
active: l.active,
|
|
1374
|
+
name: l.name,
|
|
1375
|
+
oob_channel: l.oob_channel
|
|
1366
1376
|
});
|
|
1367
1377
|
}
|
|
1368
1378
|
return { authenticators: a };
|
|
@@ -1390,7 +1400,7 @@ class cr {
|
|
|
1390
1400
|
return { error: "server_error", error_description: "Cannot get issuer" };
|
|
1391
1401
|
const n = this.oidcConfig.issuer + (this.oidcConfig.issuer.endsWith("/") ? "" : "/") + "mfa/challenge", s = await this.post(n, {
|
|
1392
1402
|
client_id: w(this, _),
|
|
1393
|
-
client_secret: w(this,
|
|
1403
|
+
client_secret: w(this, A),
|
|
1394
1404
|
challenge_type: "otp",
|
|
1395
1405
|
mfa_token: e,
|
|
1396
1406
|
authenticator_id: t
|
|
@@ -1429,7 +1439,7 @@ class cr {
|
|
|
1429
1439
|
const s = this.oidcConfig.token_endpoint, a = await this.post(s, {
|
|
1430
1440
|
grant_type: "http://auth0.com/oauth/grant-type/mfa-otp",
|
|
1431
1441
|
client_id: w(this, _),
|
|
1432
|
-
client_secret: w(this,
|
|
1442
|
+
client_secret: w(this, A),
|
|
1433
1443
|
challenge_type: "otp",
|
|
1434
1444
|
mfa_token: e,
|
|
1435
1445
|
otp: t,
|
|
@@ -1481,7 +1491,7 @@ class cr {
|
|
|
1481
1491
|
return { error: "server_error", error_description: "Cannot get issuer" };
|
|
1482
1492
|
const n = this.oidcConfig.issuer + (this.oidcConfig.issuer.endsWith("/") ? "" : "/") + "mfa/challenge", s = await this.post(n, {
|
|
1483
1493
|
client_id: w(this, _),
|
|
1484
|
-
client_secret: w(this,
|
|
1494
|
+
client_secret: w(this, A),
|
|
1485
1495
|
challenge_type: "oob",
|
|
1486
1496
|
mfa_token: e,
|
|
1487
1497
|
authenticator_id: t
|
|
@@ -1517,7 +1527,7 @@ class cr {
|
|
|
1517
1527
|
const a = this.oidcConfig.token_endpoint, c = await this.post(a, {
|
|
1518
1528
|
grant_type: "http://auth0.com/oauth/grant-type/mfa-oob",
|
|
1519
1529
|
client_id: w(this, _),
|
|
1520
|
-
client_secret: w(this,
|
|
1530
|
+
client_secret: w(this, A),
|
|
1521
1531
|
challenge_type: "otp",
|
|
1522
1532
|
mfa_token: e,
|
|
1523
1533
|
oob_code: t,
|
|
@@ -1530,10 +1540,10 @@ class cr {
|
|
|
1530
1540
|
error_description: c.error_description
|
|
1531
1541
|
};
|
|
1532
1542
|
if (c.id_token) {
|
|
1533
|
-
const
|
|
1534
|
-
if (
|
|
1535
|
-
return
|
|
1536
|
-
c.id_payload =
|
|
1543
|
+
const l = await this.getIdPayload(c.id_token, c.access_token);
|
|
1544
|
+
if (l.error)
|
|
1545
|
+
return l;
|
|
1546
|
+
c.id_payload = l.payload;
|
|
1537
1547
|
}
|
|
1538
1548
|
return {
|
|
1539
1549
|
id_token: c.id_token,
|
|
@@ -1560,7 +1570,7 @@ class cr {
|
|
|
1560
1570
|
};
|
|
1561
1571
|
const i = this.oidcConfig.token_endpoint;
|
|
1562
1572
|
let n;
|
|
1563
|
-
n = w(this,
|
|
1573
|
+
n = w(this, A);
|
|
1564
1574
|
let s = {
|
|
1565
1575
|
grant_type: "refresh_token",
|
|
1566
1576
|
refresh_token: e,
|
|
@@ -1601,7 +1611,7 @@ class cr {
|
|
|
1601
1611
|
let i = {
|
|
1602
1612
|
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
1603
1613
|
client_id: w(this, _),
|
|
1604
|
-
client_secret: w(this,
|
|
1614
|
+
client_secret: w(this, A)
|
|
1605
1615
|
};
|
|
1606
1616
|
t && (i.scope = t);
|
|
1607
1617
|
try {
|
|
@@ -1636,7 +1646,7 @@ class cr {
|
|
|
1636
1646
|
let n = {
|
|
1637
1647
|
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
1638
1648
|
client_id: w(this, _),
|
|
1639
|
-
client_secret: w(this,
|
|
1649
|
+
client_secret: w(this, A),
|
|
1640
1650
|
device_code: e
|
|
1641
1651
|
};
|
|
1642
1652
|
try {
|
|
@@ -1744,6 +1754,22 @@ class cr {
|
|
|
1744
1754
|
return;
|
|
1745
1755
|
}
|
|
1746
1756
|
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Validates an access token, returning undefined if it is invalid.
|
|
1759
|
+
*
|
|
1760
|
+
* Does not raise exceptions.
|
|
1761
|
+
*
|
|
1762
|
+
* @param token the token to validate. To be valid, the signature must
|
|
1763
|
+
* be valid and the `type` claim in the payload must be set to `id`.
|
|
1764
|
+
* @returns the parsed payload or undefined if the token is invalid.
|
|
1765
|
+
*/
|
|
1766
|
+
async validateAccessToken(e, t) {
|
|
1767
|
+
try {
|
|
1768
|
+
return await this.tokenConsumer.tokenAuthorized(e, "access", t);
|
|
1769
|
+
} catch {
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1747
1773
|
/**
|
|
1748
1774
|
* Validatesd a token using the token consumer.
|
|
1749
1775
|
*
|
|
@@ -1751,11 +1777,11 @@ class cr {
|
|
|
1751
1777
|
* @returns the parsed JSON of the payload, or undefinedf if it is not
|
|
1752
1778
|
* valid.
|
|
1753
1779
|
*/
|
|
1754
|
-
async idTokenAuthorized(e) {
|
|
1780
|
+
async idTokenAuthorized(e, t) {
|
|
1755
1781
|
try {
|
|
1756
|
-
return await this.tokenConsumer.tokenAuthorized(e, "id");
|
|
1757
|
-
} catch (
|
|
1758
|
-
d.logger.warn(h({ err:
|
|
1782
|
+
return await this.tokenConsumer.tokenAuthorized(e, "id", t);
|
|
1783
|
+
} catch (o) {
|
|
1784
|
+
d.logger.warn(h({ err: o }));
|
|
1759
1785
|
return;
|
|
1760
1786
|
}
|
|
1761
1787
|
}
|
|
@@ -1763,7 +1789,7 @@ class cr {
|
|
|
1763
1789
|
return ar(e);
|
|
1764
1790
|
}
|
|
1765
1791
|
}
|
|
1766
|
-
_ = /* @__PURE__ */ new WeakMap(),
|
|
1792
|
+
_ = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap();
|
|
1767
1793
|
class dr {
|
|
1768
1794
|
/**
|
|
1769
1795
|
* Constrctor
|
|
@@ -1773,7 +1799,7 @@ class dr {
|
|
|
1773
1799
|
* @param options See {@link OAuthTokenConsumerBaseOptions}.
|
|
1774
1800
|
*/
|
|
1775
1801
|
constructor(e, t = {}) {
|
|
1776
|
-
if (
|
|
1802
|
+
if (u(this, "audience"), u(this, "jwtKeyType"), u(this, "jwtSecretKey"), u(this, "jwtPublicKey"), u(this, "clockTolerance", 10), u(this, "authServerBaseUrl", ""), u(this, "oidcConfig"), u(this, "keys", {}), this.audience = e, t.authServerBaseUrl && (this.authServerBaseUrl = t.authServerBaseUrl), t.jwtKeyType && (this.jwtKeyType = t.jwtKeyType), t.jwtSecretKey && (this.jwtSecretKey = t.jwtSecretKey), t.jwtPublicKey && (this.jwtPublicKey = t.jwtPublicKey), t.clockTolerance && (this.clockTolerance = t.clockTolerance), t.oidcConfig && (this.oidcConfig = t.oidcConfig), this.jwtPublicKey && !this.jwtKeyType)
|
|
1777
1803
|
throw new g(
|
|
1778
1804
|
m.Configuration,
|
|
1779
1805
|
"If specifying jwtPublic key, must also specify jwtKeyType"
|
|
@@ -1834,7 +1860,8 @@ class dr {
|
|
|
1834
1860
|
throw new g(m.Connection, "Couldn't get OIDC configuration. Either set authServerBaseUrl or set config manually");
|
|
1835
1861
|
let t;
|
|
1836
1862
|
try {
|
|
1837
|
-
|
|
1863
|
+
let o = this.authServerBaseUrl;
|
|
1864
|
+
o.endsWith("/") || (o += "/"), t = await fetch(new URL(".well-known/openid-configuration", o));
|
|
1838
1865
|
} catch (o) {
|
|
1839
1866
|
d.logger.error(h({ err: o }));
|
|
1840
1867
|
}
|
|
@@ -1912,26 +1939,26 @@ class dr {
|
|
|
1912
1939
|
* fails.
|
|
1913
1940
|
* @returns the JWT payload if the token is valid, `undefined` otherwise.
|
|
1914
1941
|
*/
|
|
1915
|
-
async tokenAuthorized(e, t) {
|
|
1942
|
+
async tokenAuthorized(e, t, o) {
|
|
1916
1943
|
if (!this.keys || Object.keys(this.keys).length == 0) {
|
|
1917
|
-
const
|
|
1918
|
-
await this.loadKeys(
|
|
1944
|
+
const n = ge(e);
|
|
1945
|
+
await this.loadKeys(n.alg);
|
|
1919
1946
|
}
|
|
1920
|
-
const
|
|
1921
|
-
if (
|
|
1922
|
-
if (
|
|
1923
|
-
const
|
|
1924
|
-
d.logger.error(h({ msg: `Invalid issuer ${
|
|
1947
|
+
const i = await this.validateToken(e);
|
|
1948
|
+
if (i) {
|
|
1949
|
+
if (i.iss != this.authServerBaseUrl) {
|
|
1950
|
+
const n = i.jti ? i.jti : i.sid ? i.sid : "";
|
|
1951
|
+
d.logger.error(h({ msg: `Invalid issuer ${i.iss} ${t} token`, hashedAccessToken: await this.hash(n) }));
|
|
1925
1952
|
return;
|
|
1926
1953
|
}
|
|
1927
|
-
if (o.aud) {
|
|
1928
|
-
const
|
|
1929
|
-
if (Array.isArray(
|
|
1930
|
-
d.logger.error(h({ msg: `Invalid audience ${
|
|
1954
|
+
if (o != !1 && i.aud) {
|
|
1955
|
+
const n = i.jti ? i.jti : i.sid ? i.sid : "";
|
|
1956
|
+
if (Array.isArray(i.aud) && !i.aud.includes(this.audience) || !Array.isArray(i.aud) && i.aud != this.audience) {
|
|
1957
|
+
d.logger.error(h({ msg: `Invalid audience ${i.aud} in ${t} token`, hashedAccessToken: await this.hash(n) }));
|
|
1931
1958
|
return;
|
|
1932
1959
|
}
|
|
1933
1960
|
}
|
|
1934
|
-
return
|
|
1961
|
+
return i;
|
|
1935
1962
|
}
|
|
1936
1963
|
}
|
|
1937
1964
|
async validateToken(e) {
|
|
@@ -1960,8 +1987,9 @@ class dr {
|
|
|
1960
1987
|
return;
|
|
1961
1988
|
}
|
|
1962
1989
|
return n;
|
|
1963
|
-
} catch {
|
|
1964
|
-
|
|
1990
|
+
} catch (i) {
|
|
1991
|
+
const n = g.asCrossauthError(i);
|
|
1992
|
+
d.logger.debug(h({ err: n })), d.logger.warn(h({ msg: "Access token did not validate", cerr: n }));
|
|
1965
1993
|
return;
|
|
1966
1994
|
}
|
|
1967
1995
|
}
|
|
@@ -2005,28 +2033,29 @@ class Re {
|
|
|
2005
2033
|
this.autoRefreshActive = !1, d.logger.debug(h({ msg: "Stopping auto refresh" }));
|
|
2006
2034
|
}
|
|
2007
2035
|
async scheduleAutoRefresh(e, t) {
|
|
2008
|
-
|
|
2009
|
-
|
|
2036
|
+
let o;
|
|
2037
|
+
const i = this.tokenProvider.getCsrfToken(), n = i ? await i : void 0, s = await this.tokenProvider.getTokenExpiries([...e, "refresh"], n);
|
|
2038
|
+
if (s.refresh == null) {
|
|
2010
2039
|
d.logger.debug(h({ msg: "No refresh token found" }));
|
|
2011
2040
|
return;
|
|
2012
2041
|
}
|
|
2013
|
-
const
|
|
2014
|
-
let
|
|
2015
|
-
if ((!
|
|
2042
|
+
const a = Date.now();
|
|
2043
|
+
let c = s.id;
|
|
2044
|
+
if ((!c || s.access && s.access < c) && (c = s.access), !c) {
|
|
2016
2045
|
d.logger.debug(h({ msg: "No tokens expire" }));
|
|
2017
2046
|
return;
|
|
2018
2047
|
}
|
|
2019
|
-
|
|
2020
|
-
if (
|
|
2048
|
+
let l = c * 1e3 - a - pe;
|
|
2049
|
+
if (l < 0 && o != null && o <= 0) {
|
|
2021
2050
|
d.logger.debug(h({ msg: "Expiry time has passed" }));
|
|
2022
2051
|
return;
|
|
2023
2052
|
}
|
|
2024
|
-
if (
|
|
2053
|
+
if (l < 0 && (l = 0), s.refresh && s.refresh - pe < l) {
|
|
2025
2054
|
d.logger.debug(h({ msg: "Refresh token has expired" }));
|
|
2026
2055
|
return;
|
|
2027
2056
|
}
|
|
2028
|
-
let
|
|
2029
|
-
d.logger.debug(h({ msg: `Waiting ${
|
|
2057
|
+
let y = (k) => new Promise((b) => setTimeout(b, k));
|
|
2058
|
+
d.logger.debug(h({ msg: `Waiting ${l} before refreshing tokens` })), o = l, await y(l), await this.autoRefresh(e, n, t);
|
|
2030
2059
|
}
|
|
2031
2060
|
async autoRefresh(e, t, o) {
|
|
2032
2061
|
if (this.autoRefreshActive) {
|
|
@@ -2052,19 +2081,25 @@ class Re {
|
|
|
2052
2081
|
},
|
|
2053
2082
|
"refresh"
|
|
2054
2083
|
);
|
|
2055
|
-
|
|
2084
|
+
c.ok || d.logger.error(h({ msg: "Failed auto refreshing tokens", status: c.status }));
|
|
2085
|
+
try {
|
|
2086
|
+
i = await c.json();
|
|
2087
|
+
} catch {
|
|
2088
|
+
d.logger.error(h({ msg: "/refresh returned a non-JSON response " + (i ? await i.text() : void 0) })), i = { ok: !1, error: "Unknown" };
|
|
2089
|
+
}
|
|
2090
|
+
if (i != null && i.ok) {
|
|
2056
2091
|
await this.scheduleAutoRefresh(e, o), n = !0;
|
|
2057
2092
|
try {
|
|
2058
2093
|
await this.tokenProvider.receiveTokens(i);
|
|
2059
|
-
} catch (
|
|
2060
|
-
const y = g.asCrossauthError(
|
|
2061
|
-
o ? o("Couldn't receive tokens", y) : (d.logger.debug(h({ err:
|
|
2094
|
+
} catch (l) {
|
|
2095
|
+
const y = g.asCrossauthError(l);
|
|
2096
|
+
o ? o("Couldn't receive tokens", y) : (d.logger.debug(h({ err: l })), d.logger.error(h({ msg: "Error receiving tokens", cerr: y })));
|
|
2062
2097
|
}
|
|
2063
2098
|
} else
|
|
2064
2099
|
s < Q ? (d.logger.error(h({ msg: `Failed auto refreshing tokens. Retrying in ${ae} seconds` })), await ((y) => new Promise((k) => setTimeout(k, y)))(ae * 1e3)) : (d.logger.error(h({ msg: "Failed auto refreshing tokens. Number of retries exceeded" })), o && o("Failed auto refreshing tokens")), s++;
|
|
2065
2100
|
} catch (a) {
|
|
2066
2101
|
const c = g.asCrossauthError(a);
|
|
2067
|
-
d.logger.debug(h({ err: c })), s < Q ? (d.logger.error(h({ msg: `Failed auto refreshing tokens. Retrying in ${Q} seconds` })), await ((y) => new Promise((k) => setTimeout(k, y)))(ae)) : (d.logger.error(h({ msg: "Failed auto refreshing tokens. Number of retries exceeded" })), o && o(c.message, c)), s++;
|
|
2102
|
+
d.logger.debug(h({ err: c })), s < Q ? (d.logger.error(h({ msg: `Failed auto refreshing tokens. Retrying in ${Q} seconds` })), await ((y) => new Promise((k) => setTimeout(k, y)))(ae * 1e3)) : (d.logger.error(h({ msg: "Failed auto refreshing tokens. Number of retries exceeded" })), o && o(c.message, c)), s++;
|
|
2068
2103
|
}
|
|
2069
2104
|
}
|
|
2070
2105
|
}
|
|
@@ -2134,7 +2169,7 @@ class Ie {
|
|
|
2134
2169
|
this.pollingActive = !1, o("expired_token", "Timeout waiting for authorization");
|
|
2135
2170
|
else if (s.error == "authorization_pending" || s.error == "slow_down") {
|
|
2136
2171
|
s.error == "slow_down" && (t += 5);
|
|
2137
|
-
let a = s.interval ?? t, c = (
|
|
2172
|
+
let a = s.interval ?? t, c = (l) => new Promise((y) => setTimeout(y, l));
|
|
2138
2173
|
d.logger.debug(h({ msg: "device code poll: waiting " + String(a) + " seconds" })), await c(a * 1e3), this.pollingActive && this.poll(e, t, o);
|
|
2139
2174
|
} else s.error ? (this.pollingActive = !1, o("error", s.error_description ?? s.error)) : (this.pollingActive = !1, o("complete"));
|
|
2140
2175
|
}
|
|
@@ -2374,13 +2409,22 @@ class ur {
|
|
|
2374
2409
|
* expire, or `undefined` if the token does not exist
|
|
2375
2410
|
*/
|
|
2376
2411
|
async getTokenExpiries(e, t) {
|
|
2377
|
-
const o = await this.getTokens(t)
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2412
|
+
const o = await this.getTokens(t);
|
|
2413
|
+
try {
|
|
2414
|
+
const i = e.includes("id") ? (o == null ? void 0 : o.id_token) ?? null : null, n = e.includes("access") ? (o == null ? void 0 : o.access_token) ?? null : null, s = e.includes("refresh") ? (o == null ? void 0 : o.refresh_token) ?? null : null;
|
|
2415
|
+
let a, c, l;
|
|
2416
|
+
return i && (a = i.exp ? i.exp : null), n && (c = n.exp ? n.exp : null), s && (l = s.exp ? s.exp : null), {
|
|
2417
|
+
id: a,
|
|
2418
|
+
access: c,
|
|
2419
|
+
refresh: l
|
|
2420
|
+
};
|
|
2421
|
+
} catch {
|
|
2422
|
+
return d.logger.error(h({ msg: "getTokenExpiries received non JSON response " + o })), {
|
|
2423
|
+
id: 0,
|
|
2424
|
+
access: 0,
|
|
2425
|
+
refresh: 0
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2384
2428
|
}
|
|
2385
2429
|
/**
|
|
2386
2430
|
* Makes a fetch, adding in the requested token
|
|
@@ -2559,12 +2603,12 @@ class gr extends cr {
|
|
|
2559
2603
|
if (t.origin + t.pathname != this.redirect_uri) return;
|
|
2560
2604
|
const o = new URLSearchParams(window.location.search);
|
|
2561
2605
|
let i, n, s, a;
|
|
2562
|
-
for (const [
|
|
2563
|
-
|
|
2606
|
+
for (const [l, y] of o)
|
|
2607
|
+
l == "code" && (i = y), l == "state" && (n = y), l == "error" && (s = y), l == "error_description" && (a = y);
|
|
2564
2608
|
if (!s && !i) return;
|
|
2565
2609
|
if (s) {
|
|
2566
|
-
const
|
|
2567
|
-
throw d.logger.debug(h({ err:
|
|
2610
|
+
const l = g.fromOAuthError(s, a);
|
|
2611
|
+
throw d.logger.debug(h({ err: l })), d.logger.error(h({ cerr: l, msg: "Error from authorize endpoint: " + s })), l;
|
|
2568
2612
|
}
|
|
2569
2613
|
if (p(this, B) && n != p(this, B))
|
|
2570
2614
|
return {
|
|
@@ -2573,8 +2617,8 @@ class gr extends cr {
|
|
|
2573
2617
|
};
|
|
2574
2618
|
const c = await this.redirectEndpoint(i, this.scope, p(this, V), s, a);
|
|
2575
2619
|
if (c.error) {
|
|
2576
|
-
const
|
|
2577
|
-
throw d.logger.debug(h({ err:
|
|
2620
|
+
const l = g.fromOAuthError(c.error, a);
|
|
2621
|
+
throw d.logger.debug(h({ err: l })), d.logger.error(h({ cerr: l, msg: "Error from redirect endpoint: " + c.error })), l;
|
|
2578
2622
|
}
|
|
2579
2623
|
return await this.receiveTokens(c), c;
|
|
2580
2624
|
}
|
|
@@ -2662,8 +2706,8 @@ class gr extends cr {
|
|
|
2662
2706
|
...s
|
|
2663
2707
|
}
|
|
2664
2708
|
);
|
|
2665
|
-
let
|
|
2666
|
-
return c.body && (
|
|
2709
|
+
let l = null;
|
|
2710
|
+
return c.body && (l = await c.json()), { status: c.status, body: l };
|
|
2667
2711
|
}
|
|
2668
2712
|
///////////////////////////////////////////////////////////
|
|
2669
2713
|
// OAuthTokenProvider interface
|