@voltro/plugin-auth-workos 0.89.2 → 0.90.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/CHANGELOG.md +1822 -0
- package/dist/index.d.ts +12 -1
- package/dist/oauth.js +28 -16
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -120,7 +120,18 @@ export declare const workosDeleteMembership: (o: ApiCallOptions & {
|
|
|
120
120
|
|
|
121
121
|
export declare class WorkosExchangeError extends Error {
|
|
122
122
|
readonly status: number;
|
|
123
|
-
|
|
123
|
+
/** The provider's error class (`invalid_grant`, `invalid_client`, …) when
|
|
124
|
+
* the response body named one; null otherwise. The class is what an
|
|
125
|
+
* operator needs to tell a spent code from a wrong client secret — it
|
|
126
|
+
* carries no code, token or secret, so it is safe to log. */
|
|
127
|
+
readonly code: string | null;
|
|
128
|
+
/** The provider's `x-request-id` of the refused request, for a support
|
|
129
|
+
* conversation with WorkOS. Null when the response carried none. */
|
|
130
|
+
readonly requestId: string | null;
|
|
131
|
+
constructor(status: number, message: string, detail?: {
|
|
132
|
+
readonly code?: string | null;
|
|
133
|
+
readonly requestId?: string | null;
|
|
134
|
+
});
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
export declare interface WorkosExchangeOptions {
|
package/dist/oauth.js
CHANGED
|
@@ -20,17 +20,29 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
20
20
|
};
|
|
21
21
|
}, c = class extends Error {
|
|
22
22
|
status;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
code;
|
|
24
|
+
requestId;
|
|
25
|
+
constructor(e, t, n = {}) {
|
|
26
|
+
super(t), this.status = e, this.name = "WorkosExchangeError", this.code = n.code ?? null, this.requestId = n.requestId ?? null;
|
|
25
27
|
}
|
|
26
|
-
}, l =
|
|
28
|
+
}, l = (e) => {
|
|
29
|
+
try {
|
|
30
|
+
let t = JSON.parse(e);
|
|
31
|
+
return typeof t.error == "string" && /^[a-z0-9_]{1,64}$/.test(t.error) ? t.error : null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}, u = class extends c {
|
|
27
36
|
constructor(e) {
|
|
28
37
|
super(400, e), this.name = "WorkosStateMismatchError";
|
|
29
38
|
}
|
|
30
|
-
},
|
|
39
|
+
}, d = async (e) => {
|
|
31
40
|
if (!e.ok) {
|
|
32
41
|
let t = await e.text().catch(() => "");
|
|
33
|
-
throw new c(e.status, `WorkOS authenticate failed (${e.status}): ${t.slice(0, 200)}
|
|
42
|
+
throw new c(e.status, `WorkOS authenticate failed (${e.status}): ${t.slice(0, 200)}`, {
|
|
43
|
+
code: l(t),
|
|
44
|
+
requestId: e.headers.get("x-request-id")
|
|
45
|
+
});
|
|
34
46
|
}
|
|
35
47
|
let t = await e.json(), n = t.user;
|
|
36
48
|
if (!n?.id || !n.email) throw new c(e.status, "WorkOS authenticate response missing user id/email");
|
|
@@ -41,9 +53,9 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
41
53
|
firstName: n.first_name ?? null,
|
|
42
54
|
lastName: n.last_name ?? null,
|
|
43
55
|
organizationId: t.organization_id ?? null,
|
|
44
|
-
sessionId:
|
|
56
|
+
sessionId: f(t.access_token)
|
|
45
57
|
};
|
|
46
|
-
},
|
|
58
|
+
}, f = (e) => {
|
|
47
59
|
let t = e?.split(".")[1];
|
|
48
60
|
if (!t) return null;
|
|
49
61
|
try {
|
|
@@ -52,16 +64,16 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
52
64
|
} catch {
|
|
53
65
|
return null;
|
|
54
66
|
}
|
|
55
|
-
},
|
|
67
|
+
}, p = (e) => {
|
|
56
68
|
if (!e.sessionId) throw Error("workosLogoutUrl: `sessionId` is required");
|
|
57
69
|
let t = new URLSearchParams({ session_id: e.sessionId });
|
|
58
70
|
return e.returnTo && t.set("return_to", e.returnTo), `${e.apiBase ?? r}/user_management/sessions/logout?${t.toString()}`;
|
|
59
|
-
},
|
|
71
|
+
}, m = async (e) => {
|
|
60
72
|
if (!e.code) throw new c(400, "workosAuthenticateWithCode: missing `code`");
|
|
61
|
-
if (!e.expectedState) throw new
|
|
62
|
-
if (!e.state || !n(e.state, e.expectedState)) throw new
|
|
73
|
+
if (!e.expectedState) throw new u("workosAuthenticateWithCode: no `expectedState` — the login was never started by this server, or the state cookie expired. Refusing to exchange the code.");
|
|
74
|
+
if (!e.state || !n(e.state, e.expectedState)) throw new u("workosAuthenticateWithCode: `state` does not match the value minted for this browser (possible CSRF).");
|
|
63
75
|
if (!e.codeVerifier) throw new c(400, "workosAuthenticateWithCode: missing `codeVerifier` (PKCE)");
|
|
64
|
-
return
|
|
76
|
+
return d(await (e.fetchImpl ?? fetch)(`${e.apiBase ?? r}/user_management/authenticate`, {
|
|
65
77
|
method: "POST",
|
|
66
78
|
headers: { "content-type": "application/json" },
|
|
67
79
|
body: JSON.stringify({
|
|
@@ -72,7 +84,7 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
72
84
|
code_verifier: e.codeVerifier
|
|
73
85
|
})
|
|
74
86
|
}));
|
|
75
|
-
},
|
|
87
|
+
}, h = async (e) => {
|
|
76
88
|
if (!e.email) throw new c(400, "workosSendMagicAuthCode: missing `email`");
|
|
77
89
|
let t = await (e.fetchImpl ?? fetch)(`${e.apiBase ?? r}/user_management/magic_auth`, {
|
|
78
90
|
method: "POST",
|
|
@@ -86,10 +98,10 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
86
98
|
let e = await t.text().catch(() => "");
|
|
87
99
|
throw new c(t.status, `WorkOS magic-auth send failed (${t.status}): ${e.slice(0, 200)}`);
|
|
88
100
|
}
|
|
89
|
-
},
|
|
101
|
+
}, g = async (e) => {
|
|
90
102
|
if (!e.code) throw new c(400, "workosAuthenticateWithMagicAuth: missing `code`");
|
|
91
103
|
if (!e.email) throw new c(400, "workosAuthenticateWithMagicAuth: missing `email`");
|
|
92
|
-
return
|
|
104
|
+
return d(await (e.fetchImpl ?? fetch)(`${e.apiBase ?? r}/user_management/authenticate`, {
|
|
93
105
|
method: "POST",
|
|
94
106
|
headers: { "content-type": "application/json" },
|
|
95
107
|
body: JSON.stringify({
|
|
@@ -101,4 +113,4 @@ var r = "https://api.workos.com", i = (e) => e.toString("base64url"), a = () =>
|
|
|
101
113
|
})
|
|
102
114
|
}));
|
|
103
115
|
};
|
|
104
|
-
export { c as WorkosExchangeError,
|
|
116
|
+
export { c as WorkosExchangeError, u as WorkosStateMismatchError, m as workosAuthenticateWithCode, g as workosAuthenticateWithMagicAuth, s as workosBeginLogin, p as workosLogoutUrl, h as workosSendMagicAuthCode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-auth-workos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"description": "WorkOS-backed AuthStrategy for the Voltro framework. Verifies WorkOS AuthKit/SSO JWTs via JWKS and maps `org_id`→tenant. Composes via @voltro/protocol AuthStrategy alongside other IdP plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=24.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@voltro/protocol": "0.
|
|
36
|
+
"@voltro/protocol": "0.90.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"effect": "4.1.2"
|