@nightowlsdev/auth-auth0 0.1.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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/index.cjs +101 -0
- package/dist/index.d.cts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +75 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Night Owls contributors
|
|
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,87 @@
|
|
|
1
|
+
# @nightowlsdev/auth-auth0
|
|
2
|
+
|
|
3
|
+
An Auth0 `AuthProvider` for `@nightowlsdev/core`. It verifies an Auth0-issued access token with
|
|
4
|
+
`jose` against Auth0's **public JWKS** and maps it into a Night Owls `AuthContext`
|
|
5
|
+
(`{ tenantId, userId, capabilities }`). It is a stateless, offline-capable verifier — no
|
|
6
|
+
Auth0 Management API, no secrets — wired into a runner so identity is resolved server-side
|
|
7
|
+
at the request boundary, never from the body (CONTRACTS §2).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @nightowlsdev/auth-auth0 @nightowlsdev/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`jose` (^6) is a direct dependency. There are no other peers besides `@nightowlsdev/core`.
|
|
16
|
+
|
|
17
|
+
## How it verifies (public JWKS only)
|
|
18
|
+
|
|
19
|
+
- `createRemoteJWKSet(new URL(issuer + ".well-known/jwks.json"))` is built **once at
|
|
20
|
+
factory scope** — `jose` caches the keys, so repeated requests don't re-fetch.
|
|
21
|
+
- Each request: parse `Authorization: Bearer <jwt>` (the `Bearer` prefix is matched
|
|
22
|
+
case-insensitively; a missing token returns `null`), then
|
|
23
|
+
`jwtVerify(token, JWKS, { issuer, audience })`. Any verification failure (bad
|
|
24
|
+
signature, expired, wrong issuer/audience) returns `null` ⇒ the runner answers `401`.
|
|
25
|
+
- Only **public** signing keys are used. No client secret, no service credential.
|
|
26
|
+
|
|
27
|
+
### Auth0 issuer needs the trailing slash
|
|
28
|
+
|
|
29
|
+
Auth0 stamps the `iss` claim as `https://<tenant>.auth0.com/` **with** a trailing slash,
|
|
30
|
+
and the JWKS lives at `<issuer>.well-known/jwks.json`. Pass `issuerBaseUrl` either way —
|
|
31
|
+
the provider normalizes it to end in `/` once at construction, so both
|
|
32
|
+
`https://tenant.auth0.com` and `https://tenant.auth0.com/` work and `jwtVerify`'s
|
|
33
|
+
`issuer` check matches the token exactly.
|
|
34
|
+
|
|
35
|
+
## Claim mapping
|
|
36
|
+
|
|
37
|
+
| `AuthContext` | Source | Default |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `userId` | `sub` (must be a string) | — (required; non-string ⇒ `null`) |
|
|
40
|
+
| `tenantId` | `payload[orgClaim]` (default `org_id`, if a string) | `'default'` |
|
|
41
|
+
| `capabilities` | `payload[rolesClaim]` (default `permissions`, if an array) | `undefined` |
|
|
42
|
+
|
|
43
|
+
### `allowedOrgs` fails closed
|
|
44
|
+
|
|
45
|
+
When `allowedOrgs` is configured, a token is admitted **only** if its org claim is a
|
|
46
|
+
string **and** is in the list. A token with **no** org claim (or a non-string org claim)
|
|
47
|
+
is **rejected** when `allowedOrgs` is set — it is **not** silently dropped into the
|
|
48
|
+
`'default'` tenant. (Without `allowedOrgs`, an org-less token maps to `tenantId:
|
|
49
|
+
'default'` as a single-tenant convenience.)
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { auth0Auth } from "@nightowlsdev/auth-auth0";
|
|
55
|
+
|
|
56
|
+
const auth = auth0Auth({
|
|
57
|
+
issuerBaseUrl: process.env.AUTH0_ISSUER_BASE_URL!, // https://<tenant>.auth0.com/
|
|
58
|
+
audience: process.env.AUTH0_AUDIENCE!, // your API identifier
|
|
59
|
+
// orgClaim: "org_id", // claim mapped to tenantId
|
|
60
|
+
// rolesClaim: "permissions", // claim mapped to capabilities (if an array)
|
|
61
|
+
// allowedOrgs: ["org-123"], // optional allow-list (fails closed)
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then hand it to a runner:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { createNextjsRunner } from "@nightowlsdev/runner-nextjs";
|
|
69
|
+
const runner = createNextjsRunner({ engine, auth, storage });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Options
|
|
73
|
+
|
|
74
|
+
| Option | Default | Notes |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| `issuerBaseUrl` | — | Auth0 issuer; trailing slash auto-normalized |
|
|
77
|
+
| `audience` | — | API identifier checked against the `aud` claim |
|
|
78
|
+
| `orgClaim` | `"org_id"` | token claim mapped to `tenantId` |
|
|
79
|
+
| `rolesClaim` | `"permissions"` | token claim mapped to `capabilities` (if an array) |
|
|
80
|
+
| `allowedOrgs` | `undefined` | optional org allow-list; when set, fails closed |
|
|
81
|
+
| `jwks` | remote JWKS | test/advanced override for the key resolver (inject a local JWKS) |
|
|
82
|
+
|
|
83
|
+
## Testing
|
|
84
|
+
|
|
85
|
+
The provider accepts an injectable `jwks` resolver, so tests sign a token with a generated
|
|
86
|
+
keypair and verify against a local JWKS (`createLocalJWKSet`) — real RS256 verification,
|
|
87
|
+
fully hermetic, no network and no Auth0 tenant.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
auth0Auth: () => auth0Auth,
|
|
24
|
+
nightOwlsPlugin: () => nightOwlsPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_jose = require("jose");
|
|
28
|
+
|
|
29
|
+
// src/plugin.ts
|
|
30
|
+
var nightOwlsPlugin = {
|
|
31
|
+
name: "auth-auth0",
|
|
32
|
+
version: "0.0.0",
|
|
33
|
+
kind: "auth",
|
|
34
|
+
pkg: "@nightowlsdev/auth-auth0",
|
|
35
|
+
description: "Auth0 \u2014 verify the access token (RS256/JWKS), map the org claim \u2192 tenant. Install ONE auth provider.",
|
|
36
|
+
env: [
|
|
37
|
+
{
|
|
38
|
+
key: "AUTH0_ISSUER_BASE_URL",
|
|
39
|
+
example: "https://YOUR_TENANT.us.auth0.com",
|
|
40
|
+
comment: "Auth0 issuer (the trailing slash is normalized; JWKS resolved from /.well-known/jwks.json)"
|
|
41
|
+
},
|
|
42
|
+
{ key: "AUTH0_AUDIENCE", example: "", comment: "API identifier the access token is issued for" }
|
|
43
|
+
],
|
|
44
|
+
config: {
|
|
45
|
+
import: "import { auth0Auth } from '@nightowlsdev/auth-auth0';",
|
|
46
|
+
snippet: "auth = auth0Auth({ issuerBaseUrl: env.AUTH0_ISSUER_BASE_URL, audience: env.AUTH0_AUDIENCE });",
|
|
47
|
+
marker: "auth"
|
|
48
|
+
},
|
|
49
|
+
// Print-only (idempotent) — runs on init/install + `owl init auth-auth0`. NEVER connects anywhere.
|
|
50
|
+
init: (ctx) => {
|
|
51
|
+
ctx.log(
|
|
52
|
+
"Auth0 auth wired \u2014 set AUTH0_ISSUER_BASE_URL + AUTH0_AUDIENCE. Install ONE auth provider (reconcile a duplicate auth = \u2026 if you installed two)."
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
commands: [
|
|
56
|
+
{
|
|
57
|
+
name: "info",
|
|
58
|
+
description: "Show the env + config this auth adapter contributes.",
|
|
59
|
+
// PURE — no network. Reads only the static manifest data.
|
|
60
|
+
run: (ctx) => {
|
|
61
|
+
ctx.log("env: AUTH0_ISSUER_BASE_URL, AUTH0_AUDIENCE");
|
|
62
|
+
ctx.log("config: auth = auth0Auth({ issuerBaseUrl, audience })");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/index.ts
|
|
69
|
+
function auth0Auth(o) {
|
|
70
|
+
const orgClaim = o.orgClaim ?? "org_id";
|
|
71
|
+
const rolesClaim = o.rolesClaim ?? "permissions";
|
|
72
|
+
const issuer = o.issuerBaseUrl.endsWith("/") ? o.issuerBaseUrl : `${o.issuerBaseUrl}/`;
|
|
73
|
+
const JWKS = o.jwks ?? (0, import_jose.createRemoteJWKSet)(new URL(`${issuer}.well-known/jwks.json`));
|
|
74
|
+
return {
|
|
75
|
+
async authenticate(req) {
|
|
76
|
+
const jwt = req.headers.get("authorization")?.replace(/^Bearer\s+/i, "");
|
|
77
|
+
if (!jwt) return null;
|
|
78
|
+
let payload;
|
|
79
|
+
try {
|
|
80
|
+
({ payload } = await (0, import_jose.jwtVerify)(jwt, JWKS, { issuer, audience: o.audience }));
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const userId = typeof payload.sub === "string" ? payload.sub : null;
|
|
85
|
+
if (!userId) return null;
|
|
86
|
+
const org = payload[orgClaim];
|
|
87
|
+
if (o.allowedOrgs && !(typeof org === "string" && o.allowedOrgs.includes(org))) return null;
|
|
88
|
+
const roles = payload[rolesClaim];
|
|
89
|
+
return {
|
|
90
|
+
tenantId: typeof org === "string" ? org : "default",
|
|
91
|
+
userId,
|
|
92
|
+
capabilities: Array.isArray(roles) ? roles : void 0
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
auth0Auth,
|
|
100
|
+
nightOwlsPlugin
|
|
101
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { JWTVerifyGetKey } from 'jose';
|
|
2
|
+
import { AuthProvider } from '@nightowlsdev/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Night Owls adapter plugin manifest for Auth0. `@nightowlsdev/cli` discovers this from the host's installed
|
|
6
|
+
* `@nightowlsdev/*` deps, dynamic-imports it, and acts on it declaratively:
|
|
7
|
+
* - `env` → merged into `.env.example` (idempotent, only if the KEY is absent),
|
|
8
|
+
* - `config` → the `import` + wiring `snippet` inserted at the `// nightowls:auth` marker (assigns `auth`),
|
|
9
|
+
* - `init` → a print-only hook run after the wiring (it NEVER connects to a DB/network),
|
|
10
|
+
* - `commands`→ `owl auth-auth0 <cmd>` subcommands (e.g. `info` — pure, no network).
|
|
11
|
+
*
|
|
12
|
+
* Auth providers are MUTUALLY EXCLUSIVE — install ONE (`auth-auth0` OR `auth-supabase`). If you install
|
|
13
|
+
* both, reconcile the duplicate `auth = …` assignment in `nightowls.config.ts` (keep one).
|
|
14
|
+
*
|
|
15
|
+
* This object STRUCTURALLY matches the CLI's `NightOwlsPlugin` type but does NOT import it (no dependency
|
|
16
|
+
* cycle): all codegen lives in `@nightowlsdev/cli`; this adapter stays data-only. The `init`/command handler
|
|
17
|
+
* contexts are typed STRUCTURALLY (local `Ctx`/inline shapes) — never importing `@nightowlsdev/cli`.
|
|
18
|
+
*/
|
|
19
|
+
/** Structural context for this adapter's pure command handlers — matches the CLI's PluginCommandContext. */
|
|
20
|
+
type Ctx = {
|
|
21
|
+
cwd: string;
|
|
22
|
+
log: (m: string) => void;
|
|
23
|
+
args: string[];
|
|
24
|
+
options: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
declare const nightOwlsPlugin: {
|
|
27
|
+
readonly name: "auth-auth0";
|
|
28
|
+
readonly version: "0.0.0";
|
|
29
|
+
readonly kind: "auth";
|
|
30
|
+
readonly pkg: "@nightowlsdev/auth-auth0";
|
|
31
|
+
readonly description: "Auth0 — verify the access token (RS256/JWKS), map the org claim → tenant. Install ONE auth provider.";
|
|
32
|
+
readonly env: readonly [{
|
|
33
|
+
readonly key: "AUTH0_ISSUER_BASE_URL";
|
|
34
|
+
readonly example: "https://YOUR_TENANT.us.auth0.com";
|
|
35
|
+
readonly comment: "Auth0 issuer (the trailing slash is normalized; JWKS resolved from /.well-known/jwks.json)";
|
|
36
|
+
}, {
|
|
37
|
+
readonly key: "AUTH0_AUDIENCE";
|
|
38
|
+
readonly example: "";
|
|
39
|
+
readonly comment: "API identifier the access token is issued for";
|
|
40
|
+
}];
|
|
41
|
+
readonly config: {
|
|
42
|
+
readonly import: "import { auth0Auth } from '@nightowlsdev/auth-auth0';";
|
|
43
|
+
readonly snippet: "auth = auth0Auth({ issuerBaseUrl: env.AUTH0_ISSUER_BASE_URL, audience: env.AUTH0_AUDIENCE });";
|
|
44
|
+
readonly marker: "auth";
|
|
45
|
+
};
|
|
46
|
+
readonly init: (ctx: {
|
|
47
|
+
cwd: string;
|
|
48
|
+
log: (m: string) => void;
|
|
49
|
+
}) => void;
|
|
50
|
+
readonly commands: readonly [{
|
|
51
|
+
readonly name: "info";
|
|
52
|
+
readonly description: "Show the env + config this auth adapter contributes.";
|
|
53
|
+
readonly run: (ctx: Ctx) => void;
|
|
54
|
+
}];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
interface Auth0AuthOpts {
|
|
58
|
+
issuerBaseUrl: string;
|
|
59
|
+
audience: string;
|
|
60
|
+
orgClaim?: string;
|
|
61
|
+
rolesClaim?: string;
|
|
62
|
+
allowedOrgs?: string[];
|
|
63
|
+
/** Test/advanced override for the JWKS resolver. Defaults to createRemoteJWKSet(issuer + .well-known/jwks.json). */
|
|
64
|
+
jwks?: JWTVerifyGetKey;
|
|
65
|
+
}
|
|
66
|
+
declare function auth0Auth(o: Auth0AuthOpts): AuthProvider;
|
|
67
|
+
|
|
68
|
+
export { type Auth0AuthOpts, auth0Auth, nightOwlsPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { JWTVerifyGetKey } from 'jose';
|
|
2
|
+
import { AuthProvider } from '@nightowlsdev/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Night Owls adapter plugin manifest for Auth0. `@nightowlsdev/cli` discovers this from the host's installed
|
|
6
|
+
* `@nightowlsdev/*` deps, dynamic-imports it, and acts on it declaratively:
|
|
7
|
+
* - `env` → merged into `.env.example` (idempotent, only if the KEY is absent),
|
|
8
|
+
* - `config` → the `import` + wiring `snippet` inserted at the `// nightowls:auth` marker (assigns `auth`),
|
|
9
|
+
* - `init` → a print-only hook run after the wiring (it NEVER connects to a DB/network),
|
|
10
|
+
* - `commands`→ `owl auth-auth0 <cmd>` subcommands (e.g. `info` — pure, no network).
|
|
11
|
+
*
|
|
12
|
+
* Auth providers are MUTUALLY EXCLUSIVE — install ONE (`auth-auth0` OR `auth-supabase`). If you install
|
|
13
|
+
* both, reconcile the duplicate `auth = …` assignment in `nightowls.config.ts` (keep one).
|
|
14
|
+
*
|
|
15
|
+
* This object STRUCTURALLY matches the CLI's `NightOwlsPlugin` type but does NOT import it (no dependency
|
|
16
|
+
* cycle): all codegen lives in `@nightowlsdev/cli`; this adapter stays data-only. The `init`/command handler
|
|
17
|
+
* contexts are typed STRUCTURALLY (local `Ctx`/inline shapes) — never importing `@nightowlsdev/cli`.
|
|
18
|
+
*/
|
|
19
|
+
/** Structural context for this adapter's pure command handlers — matches the CLI's PluginCommandContext. */
|
|
20
|
+
type Ctx = {
|
|
21
|
+
cwd: string;
|
|
22
|
+
log: (m: string) => void;
|
|
23
|
+
args: string[];
|
|
24
|
+
options: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
declare const nightOwlsPlugin: {
|
|
27
|
+
readonly name: "auth-auth0";
|
|
28
|
+
readonly version: "0.0.0";
|
|
29
|
+
readonly kind: "auth";
|
|
30
|
+
readonly pkg: "@nightowlsdev/auth-auth0";
|
|
31
|
+
readonly description: "Auth0 — verify the access token (RS256/JWKS), map the org claim → tenant. Install ONE auth provider.";
|
|
32
|
+
readonly env: readonly [{
|
|
33
|
+
readonly key: "AUTH0_ISSUER_BASE_URL";
|
|
34
|
+
readonly example: "https://YOUR_TENANT.us.auth0.com";
|
|
35
|
+
readonly comment: "Auth0 issuer (the trailing slash is normalized; JWKS resolved from /.well-known/jwks.json)";
|
|
36
|
+
}, {
|
|
37
|
+
readonly key: "AUTH0_AUDIENCE";
|
|
38
|
+
readonly example: "";
|
|
39
|
+
readonly comment: "API identifier the access token is issued for";
|
|
40
|
+
}];
|
|
41
|
+
readonly config: {
|
|
42
|
+
readonly import: "import { auth0Auth } from '@nightowlsdev/auth-auth0';";
|
|
43
|
+
readonly snippet: "auth = auth0Auth({ issuerBaseUrl: env.AUTH0_ISSUER_BASE_URL, audience: env.AUTH0_AUDIENCE });";
|
|
44
|
+
readonly marker: "auth";
|
|
45
|
+
};
|
|
46
|
+
readonly init: (ctx: {
|
|
47
|
+
cwd: string;
|
|
48
|
+
log: (m: string) => void;
|
|
49
|
+
}) => void;
|
|
50
|
+
readonly commands: readonly [{
|
|
51
|
+
readonly name: "info";
|
|
52
|
+
readonly description: "Show the env + config this auth adapter contributes.";
|
|
53
|
+
readonly run: (ctx: Ctx) => void;
|
|
54
|
+
}];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
interface Auth0AuthOpts {
|
|
58
|
+
issuerBaseUrl: string;
|
|
59
|
+
audience: string;
|
|
60
|
+
orgClaim?: string;
|
|
61
|
+
rolesClaim?: string;
|
|
62
|
+
allowedOrgs?: string[];
|
|
63
|
+
/** Test/advanced override for the JWKS resolver. Defaults to createRemoteJWKSet(issuer + .well-known/jwks.json). */
|
|
64
|
+
jwks?: JWTVerifyGetKey;
|
|
65
|
+
}
|
|
66
|
+
declare function auth0Auth(o: Auth0AuthOpts): AuthProvider;
|
|
67
|
+
|
|
68
|
+
export { type Auth0AuthOpts, auth0Auth, nightOwlsPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
3
|
+
|
|
4
|
+
// src/plugin.ts
|
|
5
|
+
var nightOwlsPlugin = {
|
|
6
|
+
name: "auth-auth0",
|
|
7
|
+
version: "0.0.0",
|
|
8
|
+
kind: "auth",
|
|
9
|
+
pkg: "@nightowlsdev/auth-auth0",
|
|
10
|
+
description: "Auth0 \u2014 verify the access token (RS256/JWKS), map the org claim \u2192 tenant. Install ONE auth provider.",
|
|
11
|
+
env: [
|
|
12
|
+
{
|
|
13
|
+
key: "AUTH0_ISSUER_BASE_URL",
|
|
14
|
+
example: "https://YOUR_TENANT.us.auth0.com",
|
|
15
|
+
comment: "Auth0 issuer (the trailing slash is normalized; JWKS resolved from /.well-known/jwks.json)"
|
|
16
|
+
},
|
|
17
|
+
{ key: "AUTH0_AUDIENCE", example: "", comment: "API identifier the access token is issued for" }
|
|
18
|
+
],
|
|
19
|
+
config: {
|
|
20
|
+
import: "import { auth0Auth } from '@nightowlsdev/auth-auth0';",
|
|
21
|
+
snippet: "auth = auth0Auth({ issuerBaseUrl: env.AUTH0_ISSUER_BASE_URL, audience: env.AUTH0_AUDIENCE });",
|
|
22
|
+
marker: "auth"
|
|
23
|
+
},
|
|
24
|
+
// Print-only (idempotent) — runs on init/install + `owl init auth-auth0`. NEVER connects anywhere.
|
|
25
|
+
init: (ctx) => {
|
|
26
|
+
ctx.log(
|
|
27
|
+
"Auth0 auth wired \u2014 set AUTH0_ISSUER_BASE_URL + AUTH0_AUDIENCE. Install ONE auth provider (reconcile a duplicate auth = \u2026 if you installed two)."
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
commands: [
|
|
31
|
+
{
|
|
32
|
+
name: "info",
|
|
33
|
+
description: "Show the env + config this auth adapter contributes.",
|
|
34
|
+
// PURE — no network. Reads only the static manifest data.
|
|
35
|
+
run: (ctx) => {
|
|
36
|
+
ctx.log("env: AUTH0_ISSUER_BASE_URL, AUTH0_AUDIENCE");
|
|
37
|
+
ctx.log("config: auth = auth0Auth({ issuerBaseUrl, audience })");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/index.ts
|
|
44
|
+
function auth0Auth(o) {
|
|
45
|
+
const orgClaim = o.orgClaim ?? "org_id";
|
|
46
|
+
const rolesClaim = o.rolesClaim ?? "permissions";
|
|
47
|
+
const issuer = o.issuerBaseUrl.endsWith("/") ? o.issuerBaseUrl : `${o.issuerBaseUrl}/`;
|
|
48
|
+
const JWKS = o.jwks ?? createRemoteJWKSet(new URL(`${issuer}.well-known/jwks.json`));
|
|
49
|
+
return {
|
|
50
|
+
async authenticate(req) {
|
|
51
|
+
const jwt = req.headers.get("authorization")?.replace(/^Bearer\s+/i, "");
|
|
52
|
+
if (!jwt) return null;
|
|
53
|
+
let payload;
|
|
54
|
+
try {
|
|
55
|
+
({ payload } = await jwtVerify(jwt, JWKS, { issuer, audience: o.audience }));
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const userId = typeof payload.sub === "string" ? payload.sub : null;
|
|
60
|
+
if (!userId) return null;
|
|
61
|
+
const org = payload[orgClaim];
|
|
62
|
+
if (o.allowedOrgs && !(typeof org === "string" && o.allowedOrgs.includes(org))) return null;
|
|
63
|
+
const roles = payload[rolesClaim];
|
|
64
|
+
return {
|
|
65
|
+
tenantId: typeof org === "string" ? org : "default",
|
|
66
|
+
userId,
|
|
67
|
+
capabilities: Array.isArray(roles) ? roles : void 0
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
auth0Auth,
|
|
74
|
+
nightOwlsPlugin
|
|
75
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nightowlsdev/auth-auth0",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/cueplusplus/corale.git",
|
|
12
|
+
"directory": "packages/auth-auth0"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/cueplusplus/corale#readme",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"jose": "^6.2.3"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@nightowlsdev/core": "0.3.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "8.5.1",
|
|
37
|
+
"typescript": "6.0.3",
|
|
38
|
+
"vitest": "^3.2.0",
|
|
39
|
+
"@nightowlsdev/eslint-config": "0.0.0",
|
|
40
|
+
"@nightowlsdev/tsconfig": "0.0.0",
|
|
41
|
+
"@nightowlsdev/core": "0.3.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"lint": "eslint src"
|
|
48
|
+
}
|
|
49
|
+
}
|