@clivly/auth-workos 0.1.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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +45 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clivly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @clivly/auth-workos
|
|
2
|
+
|
|
3
|
+
[WorkOS](https://workos.com) implementation of Clivly's `ClivlyAuthAdapter`. Unseals the host app's AuthKit session cookie to resolve a CRM end-user's identity.
|
|
4
|
+
|
|
5
|
+
`@workos-inc/node` is a peer dependency.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createWorkOSAuthAdapter } from "@clivly/auth-workos";
|
|
9
|
+
|
|
10
|
+
const authAdapter = createWorkOSAuthAdapter({
|
|
11
|
+
apiKey: process.env.WORKOS_API_KEY!,
|
|
12
|
+
clientId: process.env.WORKOS_CLIENT_ID!,
|
|
13
|
+
cookiePassword: process.env.WORKOS_COOKIE_PASSWORD!,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const user = await authAdapter.getUser(request); // { id, email, name } | null
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core";
|
|
2
|
+
|
|
3
|
+
//#region src/map.d.ts
|
|
4
|
+
interface WorkOSLikeUser {
|
|
5
|
+
email: string;
|
|
6
|
+
firstName?: string | null;
|
|
7
|
+
id: string;
|
|
8
|
+
lastName?: string | null;
|
|
9
|
+
}
|
|
10
|
+
declare function workosUserToClivlyUser(user: WorkOSLikeUser): ClivlyUser | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.d.ts
|
|
13
|
+
interface WorkOSAuthAdapterOptions {
|
|
14
|
+
/** WorkOS API key (sk_…). */
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** WorkOS client ID (client_…). */
|
|
17
|
+
clientId: string;
|
|
18
|
+
/** Session cookie name. Defaults to `wos-session`. */
|
|
19
|
+
cookieName?: string;
|
|
20
|
+
/** Password used to unseal the AuthKit session cookie. */
|
|
21
|
+
cookiePassword: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* WorkOS → ClivlyAuthAdapter. Unseals the host app's AuthKit session cookie and
|
|
25
|
+
* resolves the CRM end-user's identity. Answers "who is this person?" only —
|
|
26
|
+
* CRM authorization lives in the separate `crm_members` layer.
|
|
27
|
+
*/
|
|
28
|
+
declare function createWorkOSAuthAdapter(options: WorkOSAuthAdapterOptions): ClivlyAuthAdapter;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { WorkOSAuthAdapterOptions, type WorkOSLikeUser, createWorkOSAuthAdapter, workosUserToClivlyUser };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WorkOS } from "@workos-inc/node";
|
|
2
|
+
//#region src/map.ts
|
|
3
|
+
function workosUserToClivlyUser(user) {
|
|
4
|
+
if (!user.email) return null;
|
|
5
|
+
const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || void 0;
|
|
6
|
+
return {
|
|
7
|
+
id: user.id,
|
|
8
|
+
email: user.email,
|
|
9
|
+
name
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function readCookie(req, name) {
|
|
13
|
+
const header = req.headers.get("cookie");
|
|
14
|
+
if (!header) return null;
|
|
15
|
+
for (const part of header.split(";")) {
|
|
16
|
+
const eq = part.indexOf("=");
|
|
17
|
+
if (eq === -1) continue;
|
|
18
|
+
if (part.slice(0, eq).trim() === name) return decodeURIComponent(part.slice(eq + 1).trim());
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/index.ts
|
|
24
|
+
const DEFAULT_COOKIE_NAME = "wos-session";
|
|
25
|
+
/**
|
|
26
|
+
* WorkOS → ClivlyAuthAdapter. Unseals the host app's AuthKit session cookie and
|
|
27
|
+
* resolves the CRM end-user's identity. Answers "who is this person?" only —
|
|
28
|
+
* CRM authorization lives in the separate `crm_members` layer.
|
|
29
|
+
*/
|
|
30
|
+
function createWorkOSAuthAdapter(options) {
|
|
31
|
+
const workos = new WorkOS(options.apiKey, { clientId: options.clientId });
|
|
32
|
+
const cookieName = options.cookieName ?? DEFAULT_COOKIE_NAME;
|
|
33
|
+
return { async getUser(req) {
|
|
34
|
+
const sessionData = readCookie(req, cookieName);
|
|
35
|
+
if (!sessionData) return null;
|
|
36
|
+
const result = await workos.userManagement.loadSealedSession({
|
|
37
|
+
sessionData,
|
|
38
|
+
cookiePassword: options.cookiePassword
|
|
39
|
+
}).authenticate();
|
|
40
|
+
if (!result.authenticated) return null;
|
|
41
|
+
return workosUserToClivlyUser(result.user);
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createWorkOSAuthAdapter, workosUserToClivlyUser };
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clivly/auth-workos",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "WorkOS implementation of Clivly's ClivlyAuthAdapter.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@clivly/core": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@workos-inc/node": ">=7"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@workos-inc/node": "^7.75.0",
|
|
29
|
+
"tsdown": "^0.21.9",
|
|
30
|
+
"typescript": "^6",
|
|
31
|
+
"@clivly.com/config": "0.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"check-types": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.mjs",
|
|
38
|
+
"types": "./dist/index.d.mts"
|
|
39
|
+
}
|