@zenauth/node 0.2.0 → 0.2.1
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 +55 -17
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://zenauth.kenilpatel.in"><img src="https://raw.githubusercontent.com/patelkenil26/ZenAuth/main/apps/web/public/logo/zenauth-app-icon-512.png" width="72" height="72" alt="ZenAuth logo" /></a>
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">@zenauth/node</h1>
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
- Checks issuer and expiry, accepts **RS256 only**, and (optionally) that the token was issued to **your** app
|
|
7
|
-
- Fetches the user's profile (name, email) when you need it
|
|
8
|
-
- Works in any Node 18+ backend: Express, Fastify, Next.js route handlers, tRPC, Hono, ...
|
|
7
|
+
<p align="center">Verify ZenAuth access tokens and webhooks in any Node backend.</p>
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@zenauth/node"><img src="https://img.shields.io/npm/v/@zenauth/node?color=ea6a20&label=npm" alt="npm version" /></a>
|
|
11
|
+
<img src="https://img.shields.io/badge/license-MIT-ea6a20" alt="MIT license" />
|
|
12
|
+
<img src="https://img.shields.io/badge/TypeScript-types%20included-3178c6" alt="TypeScript types included" />
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://zenauth.kenilpatel.in"><b>Website</b></a> ·
|
|
17
|
+
<a href="https://zenauth.kenilpatel.in/docs"><b>Documentation</b></a> ·
|
|
18
|
+
<a href="https://zenauth.kenilpatel.in/developer"><b>Get your keys</b></a> ·
|
|
19
|
+
<a href="https://github.com/patelkenil26/ZenAuth"><b>GitHub</b></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
[ZenAuth](https://zenauth.kenilpatel.in) is an OpenID Connect authentication service. Your frontend signs users in and gets an **access token**. Your backend must never trust that token blindly: this package verifies it.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
| | |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| **Token verification** | Signature checked against your issuer's JWKS, cached and rotated |
|
|
29
|
+
| **Strict by default** | RS256 only, issuer and expiry checked, plus the client ID when you pass `clientId` |
|
|
30
|
+
| **User profile** | `getUserInfo()` for name, email, role and teams |
|
|
31
|
+
| **Webhooks** | `verifyWebhook()` for signed ZenAuth events |
|
|
32
|
+
| **Any framework** | Express, Fastify, Hono, tRPC, Next.js route handlers |
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
11
35
|
|
|
12
36
|
```bash
|
|
13
37
|
npm install @zenauth/node
|
|
14
38
|
```
|
|
15
39
|
|
|
16
|
-
|
|
40
|
+
Requires Node.js 20.19+ or 22.12+.
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
17
43
|
|
|
18
44
|
Create the verifier **once** at startup so the public keys stay cached.
|
|
19
45
|
|
|
@@ -83,9 +109,10 @@ if (!user) {
|
|
|
83
109
|
| Export | Description |
|
|
84
110
|
| --- | --- |
|
|
85
111
|
| `createZenAuth({ issuer, clientId?, clockToleranceSec? })` | Returns `{ verifyToken, getUserInfo, issuer }`. |
|
|
86
|
-
| `verifyToken(token)` | Resolves to `{ userId, clientId, scopes, expiresAt, claims }`, or throws `ZenAuthTokenError`. |
|
|
87
|
-
| `getUserInfo(accessToken)` | Verifies the token, then returns `{ sub, name?, email?, email_verified? }` (depends on granted scopes). |
|
|
112
|
+
| `verifyToken(token)` | Resolves to `{ userId, clientId, scopes, expiresAt, claims, role?, orgs? }`, or throws `ZenAuthTokenError`. |
|
|
113
|
+
| `getUserInfo(accessToken)` | Verifies the token, then returns `{ sub, name?, email?, email_verified?, role?, orgs? }` (depends on granted scopes). |
|
|
88
114
|
| `getBearerToken(header)` | Pulls the token out of an `Authorization: Bearer ...` header, or `null`. |
|
|
115
|
+
| `verifyWebhook({ payload, signature, secret, toleranceSec? })` | Returns the event `{ id, type, client_id, created_at, data }`, or throws `ZenAuthWebhookError`. |
|
|
89
116
|
| `ZenAuthTokenError` | `error.code` is one of `missing_token`, `invalid_token`, `token_expired`, `wrong_client`, `userinfo_failed`. |
|
|
90
117
|
|
|
91
118
|
## Roles, organizations and webhooks
|
|
@@ -93,9 +120,12 @@ if (!user) {
|
|
|
93
120
|
`verifyToken` and `getUserInfo` include `role` and, with the `organizations` scope, `orgs`.
|
|
94
121
|
|
|
95
122
|
`verifyWebhook({ payload, signature, secret, toleranceSec? })` checks the `ZenAuth-Signature` header and returns
|
|
96
|
-
the event, or throws `ZenAuthWebhookError`. Pass the raw request body, not parsed JSON
|
|
123
|
+
the event, or throws `ZenAuthWebhookError`. Pass the raw request body, not parsed JSON. In Express, register this
|
|
124
|
+
route **before** `express.json()` and before any sign-in middleware, because ZenAuth sends no access token:
|
|
97
125
|
|
|
98
126
|
```ts
|
|
127
|
+
import { verifyWebhook } from "@zenauth/node";
|
|
128
|
+
|
|
99
129
|
app.post("/webhooks/zenauth", express.raw({ type: "application/json" }), (req, res) => {
|
|
100
130
|
const event = verifyWebhook({
|
|
101
131
|
payload: req.body,
|
|
@@ -113,10 +143,18 @@ app.post("/webhooks/zenauth", express.raw({ type: "application/json" }), (req, r
|
|
|
113
143
|
- Treat `getUserInfo().email` as verified only when `email_verified` is `true`.
|
|
114
144
|
- Keep your own authorization rules (who can see which form). This package only proves **who** the user is.
|
|
115
145
|
|
|
116
|
-
##
|
|
146
|
+
## ZenAuth SDKs
|
|
117
147
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
| Package | Use it for |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| [@zenauth/react](https://www.npmjs.com/package/@zenauth/react) | Sign-in components, hooks and embedded forms for React apps |
|
|
151
|
+
| [@zenauth/nextjs](https://www.npmjs.com/package/@zenauth/nextjs) | Server-side sign-in, session cookie and route protection for Next.js |
|
|
152
|
+
| **@zenauth/node** (this one) | Verify access tokens and webhooks in any Node backend |
|
|
153
|
+
|
|
154
|
+
## Support
|
|
155
|
+
|
|
156
|
+
Found a bug or need help? [Open an issue](https://github.com/patelkenil26/ZenAuth/issues) or read the [documentation](https://zenauth.kenilpatel.in/docs). Please do not include client secrets, API keys or tokens in an issue.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenauth/node",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Server-side helpers for ZenAuth: verify access tokens against your ZenAuth JWKS and look up the signed-in user.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"homepage": "https://zenauth.kenilpatel.in",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/patelkenil26/ZenAuth.git",
|
|
10
|
+
"directory": "packages/node"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/patelkenil26/ZenAuth/issues"
|
|
14
|
+
},
|
|
6
15
|
"keywords": [
|
|
7
16
|
"zenauth",
|
|
8
17
|
"auth",
|
|
@@ -35,7 +44,7 @@
|
|
|
35
44
|
"LICENSE"
|
|
36
45
|
],
|
|
37
46
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
47
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
39
48
|
},
|
|
40
49
|
"publishConfig": {
|
|
41
50
|
"access": "public"
|