@columenlabs/lumen-auth 0.0.0-stage → 0.1.32

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Columen Labs
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/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ Lumen
2
+ Copyright (c) 2026 Columen Labs. Licensed under the MIT License (see LICENSE).
3
+
4
+ Lumen draws price and market charts with TradingView Lightweight Charts™
5
+ (https://github.com/tradingview/lightweight-charts), Copyright (c) 2025
6
+ TradingView, Inc., licensed under the Apache License 2.0. Lumen turns off the
7
+ chart's own logo, so per that library's NOTICE, an app that shows these charts
8
+ should link to https://www.tradingview.com/ somewhere a user can find it (an
9
+ About page or footer is enough).
10
+
11
+ The components under packages/ui/src/ui are based on shadcn/ui
12
+ (https://ui.shadcn.com), MIT License, Copyright (c) 2023 shadcn.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @columenlabs/lumen-auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lumen's sign-in checks for Workers behind Cloudflare Access: verify the token Access signs on every request, in the Worker, so a route stays closed even when the Access application is misconfigured or a request reached the Worker another way. No dependencies: Web Crypto and `fetch`, so it runs in a Worker, Bun or Node.
4
+
5
+ - Docs: https://lumen.columenlabs.com/docs/
6
+ - For agents: https://lumen.columenlabs.com/llms.txt
7
+ - Source: https://github.com/columenlabs/lumen (`packages/auth`). MIT.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ bun add @columenlabs/lumen-auth
13
+ ```
14
+
15
+ Pin it to the same exact version as the other Lumen packages.
16
+
17
+ ## Verify an Access token
18
+
19
+ ```ts
20
+ import { AccessVerifier, accessToken } from '@columenlabs/lumen-auth';
21
+
22
+ // One per isolate: the team's signing keys are fetched once and kept an hour.
23
+ const access = new AccessVerifier({
24
+ teamDomain: 'myteam.cloudflareaccess.com',
25
+ aud: [env.ACCESS_AUD], // one application's AUD tag, or several (one Worker, several hosts)
26
+ });
27
+
28
+ const who = await access.verify(accessToken(request));
29
+ if (!who) return new Response('Not found', { status: 404 });
30
+ who.email; // the person, when a person signed in
31
+ who.serviceToken; // the service token's client ID, when a service token signed in
32
+ who.sub; // Access's subject id
33
+ ```
34
+
35
+ `verify` returns `null` for a missing, malformed, expired or wrongly signed token, a token for another application (`aud`) or another team (`iss`). Only RS256 is accepted. A key id it has not seen fetches the keys again.
36
+
37
+ | Export | |
38
+ |---|---|
39
+ | `AccessVerifier(config, fetch?, now?)` | `verify(token)` → `AccessIdentity` or `null`. `fetch` and `now` are for tests |
40
+ | `AccessConfig` | `{ teamDomain, aud }` |
41
+ | `AccessIdentity` | `{ sub, email?, serviceToken? }` |
42
+ | `accessToken(request)` | The request's `Cf-Access-Jwt-Assertion`, if any |
43
+ | `ACCESS_HEADER` | `'cf-access-jwt-assertion'` |
44
+
45
+ Who Access lets in stays Access's policy; what each person may do stays the app's own. This package only proves the request came through Access.
46
+
47
+ ## Versions
48
+
49
+ 0.x: any minor may break things until 1.0. Every merge to Lumen's `main` publishes the next patch of every Lumen package; see the [releases](https://github.com/columenlabs/lumen/releases).
@@ -0,0 +1,34 @@
1
+ export interface AccessConfig {
2
+ /** e.g. `columenlabs.cloudflareaccess.com` */
3
+ teamDomain: string;
4
+ /** The Access application's AUD tag, or several applications' tags (one Worker on several hosts). */
5
+ aud: string | string[];
6
+ }
7
+ export interface AccessIdentity {
8
+ email?: string;
9
+ sub: string;
10
+ /** Service-token client ID (`common_name`) when an Access service token, not a person, signed in. */
11
+ serviceToken?: string;
12
+ }
13
+ type FetchFn = (input: string) => Promise<Response>;
14
+ /** The header Access puts its signed token in. */
15
+ export declare const ACCESS_HEADER = "cf-access-jwt-assertion";
16
+ /** A request's Access token, if it has one. */
17
+ export declare const accessToken: (request: Request) => string | undefined;
18
+ /**
19
+ * Verifies Access tokens against the team's signing keys (fetched from
20
+ * `https://<teamDomain>/cdn-cgi/access/certs`, kept an hour, fetched again for an unknown key id):
21
+ * RS256 only, the audience one of `aud`, the issuer the team, not expired and not before its time.
22
+ * Keep one per isolate so the keys are fetched once.
23
+ */
24
+ export declare class AccessVerifier {
25
+ private readonly cfg;
26
+ private readonly fetchImpl;
27
+ private readonly now;
28
+ private keys;
29
+ constructor(cfg: AccessConfig, fetchImpl?: FetchFn, now?: () => number);
30
+ private keyFor;
31
+ /** Returns the identity, or null when the token is missing/invalid. */
32
+ verify(token: string | undefined): Promise<AccessIdentity | null>;
33
+ }
34
+ export {};
package/dist/access.js ADDED
@@ -0,0 +1,93 @@
1
+ // Cloudflare Access sign-in, checked again in the Worker. Access guards a host at the edge; the
2
+ // Worker verifies its signed token (`Cf-Access-Jwt-Assertion`) on every request, so a route stays
3
+ // closed even if the Access application is misconfigured or a request reached the Worker some
4
+ // other way. No dependencies: Web Crypto and fetch only, so it runs in a Worker, Bun or Node.
5
+ const b64urlToBytes = (s) => {
6
+ const b64 = s
7
+ .replace(/-/g, '+')
8
+ .replace(/_/g, '/')
9
+ .padEnd(Math.ceil(s.length / 4) * 4, '=');
10
+ const bin = atob(b64);
11
+ const out = new Uint8Array(bin.length);
12
+ for (let i = 0; i < bin.length; i++)
13
+ out[i] = bin.charCodeAt(i);
14
+ return out;
15
+ };
16
+ const decodeJson = (s) => JSON.parse(new TextDecoder().decode(b64urlToBytes(s)));
17
+ /** The header Access puts its signed token in. */
18
+ export const ACCESS_HEADER = 'cf-access-jwt-assertion';
19
+ /** A request's Access token, if it has one. */
20
+ export const accessToken = (request) => request.headers.get(ACCESS_HEADER) ?? undefined;
21
+ /**
22
+ * Verifies Access tokens against the team's signing keys (fetched from
23
+ * `https://<teamDomain>/cdn-cgi/access/certs`, kept an hour, fetched again for an unknown key id):
24
+ * RS256 only, the audience one of `aud`, the issuer the team, not expired and not before its time.
25
+ * Keep one per isolate so the keys are fetched once.
26
+ */
27
+ export class AccessVerifier {
28
+ cfg;
29
+ fetchImpl;
30
+ now;
31
+ keys;
32
+ constructor(cfg, fetchImpl = (u) => fetch(u), now = Date.now) {
33
+ this.cfg = cfg;
34
+ this.fetchImpl = fetchImpl;
35
+ this.now = now;
36
+ }
37
+ async keyFor(kid) {
38
+ const fresh = this.keys && this.now() - this.keys.at < 60 * 60_000;
39
+ if (!fresh || !this.keys?.keys.has(kid)) {
40
+ const res = await this.fetchImpl(`https://${this.cfg.teamDomain}/cdn-cgi/access/certs`);
41
+ if (!res.ok)
42
+ throw new Error(`access certs ${res.status}`);
43
+ const { keys } = (await res.json());
44
+ const map = new Map();
45
+ for (const k of keys) {
46
+ map.set(k.kid, await crypto.subtle.importKey('jwk',
47
+ // JWK from Access's certs endpoint; the lib's JsonWebKey type isn't in scope here.
48
+ k, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, false, ['verify']));
49
+ }
50
+ this.keys = { at: this.now(), keys: map };
51
+ }
52
+ return this.keys?.keys.get(kid);
53
+ }
54
+ /** Returns the identity, or null when the token is missing/invalid. */
55
+ async verify(token) {
56
+ if (!token)
57
+ return null;
58
+ const parts = token.split('.');
59
+ if (parts.length !== 3)
60
+ return null;
61
+ const [h, p, s] = parts;
62
+ try {
63
+ const header = decodeJson(h);
64
+ if (header.alg !== 'RS256')
65
+ return null;
66
+ const key = await this.keyFor(header.kid);
67
+ if (!key)
68
+ return null;
69
+ const ok = await crypto.subtle.verify('RSASSA-PKCS1-v1_5', key, b64urlToBytes(s), new Uint8Array(new TextEncoder().encode(`${h}.${p}`)));
70
+ if (!ok)
71
+ return null;
72
+ const claims = decodeJson(p);
73
+ const nowS = this.now() / 1000;
74
+ const auds = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
75
+ const mine = Array.isArray(this.cfg.aud) ? this.cfg.aud : [this.cfg.aud];
76
+ if (!auds.some((a) => mine.includes(a)))
77
+ return null;
78
+ if (claims.iss !== `https://${this.cfg.teamDomain}`)
79
+ return null;
80
+ if (claims.exp < nowS || (claims.nbf !== undefined && claims.nbf > nowS + 60))
81
+ return null;
82
+ return {
83
+ sub: claims.sub,
84
+ email: claims.email,
85
+ // Service tokens carry no email; `common_name` is the token's client ID.
86
+ ...(claims.email || !claims.common_name ? {} : { serviceToken: claims.common_name }),
87
+ };
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ }
@@ -0,0 +1 @@
1
+ export * from './access.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './access.js';
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-auth",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.32",
4
+ "description": "Lumen's sign-in checks: Cloudflare Access tokens and service tokens, verified in the Worker.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./access": {
15
+ "types": "./dist/access.d.ts",
16
+ "default": "./dist/access.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "LICENSE",
22
+ "NOTICE"
23
+ ],
24
+ "sideEffects": [
25
+ "**/*.css"
26
+ ],
27
+ "homepage": "https://github.com/columenlabs/lumen",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/columenlabs/lumen.git",
31
+ "directory": "packages/auth"
32
+ },
33
+ "bugs": "https://github.com/columenlabs/lumen/issues",
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "dependencies": {}
39
+ }