@jeffjassky/oauth-host 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 +126 -0
- package/dist/index.cjs +2787 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2773 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -0
- package/types/index.d.ts +781 -0
- package/types/test-d.ts +320 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) __YEAR__ Jeff Jassky
|
|
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,126 @@
|
|
|
1
|
+
# @jeffjassky/oauth-host
|
|
2
|
+
|
|
3
|
+
OAuth 2.1 + OpenID Connect authorization server for an Express/Mongoose app you
|
|
4
|
+
already have. Built for the case where a user connects your API to Claude or
|
|
5
|
+
ChatGPT as an MCP connector.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jeffjassky/oauth-host
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Full docs: **https://jeffjassky.github.io/oauth-host/**
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import express from 'express';
|
|
17
|
+
import mongoose from 'mongoose';
|
|
18
|
+
import { createOAuthHost } from '@jeffjassky/oauth-host';
|
|
19
|
+
|
|
20
|
+
await mongoose.connect(process.env.MONGO_URL);
|
|
21
|
+
|
|
22
|
+
const oauth = createOAuthHost({
|
|
23
|
+
connection: mongoose,
|
|
24
|
+
issuer: 'https://api.example.com', // the PUBLIC origin
|
|
25
|
+
resources: [{ id: 'https://api.example.com/mcp', label: 'MCP server' }],
|
|
26
|
+
scopes: [
|
|
27
|
+
{ id: 'openid', label: 'Sign you in' },
|
|
28
|
+
{ id: 'contacts.read', label: 'Read your contacts' },
|
|
29
|
+
{ id: 'contacts.write', label: 'Create and edit contacts', sensitive: true },
|
|
30
|
+
],
|
|
31
|
+
consentUrl: '/settings/authorize', // your page
|
|
32
|
+
loginUrl: '/login',
|
|
33
|
+
resolveUser: (req) => req.user && { id: req.user._id, email: req.user.email },
|
|
34
|
+
loadUser: async (id) => User.findById(id).lean(),
|
|
35
|
+
signing: { keys: [{ kid: 'prod-1', privateKeyPem: process.env.OAUTH_KEY }] },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await oauth.syncIndexes(); // before the first write
|
|
39
|
+
|
|
40
|
+
const app = express();
|
|
41
|
+
app.use(express.json()); // yours, not ours
|
|
42
|
+
|
|
43
|
+
app.use(oauth.routes.discovery); // ORIGIN ROOT
|
|
44
|
+
app.use('/oauth', oauth.routes.oauth);
|
|
45
|
+
app.use('/mcp', oauth.protect('contacts.read'), mcpRouter);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Register each client once — there is no RFC 7591 dynamic client registration:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const { clientId, clientSecret } = await oauth.clients.create({
|
|
52
|
+
name: 'Claude',
|
|
53
|
+
redirectUris: ['<Claude connector callback, from their docs>'],
|
|
54
|
+
allowedScopes: ['openid', 'contacts.read'],
|
|
55
|
+
branding: { publisher: 'Anthropic' },
|
|
56
|
+
}); // secret returned once, never again
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or let Claude and ChatGPT register themselves with a [client ID metadata
|
|
60
|
+
document](https://jeffjassky.github.io/oauth-host/guide/cimd) — their
|
|
61
|
+
`client_id` is an `https://` URL serving a JSON description of themselves, and
|
|
62
|
+
there is no secret to paste. Off by default; it means an outbound fetch driven
|
|
63
|
+
by a request parameter, so it is opt-in and host-allowlisted:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
clientIdMetadata: { enabled: true, allowedHosts: ['claude.ai', 'chatgpt.com'] }
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## What it does
|
|
70
|
+
|
|
71
|
+
`authorization_code` with mandatory PKCE (S256) and `refresh_token`, for
|
|
72
|
+
confidential clients and — with client ID metadata documents enabled — public
|
|
73
|
+
ones. Signed ES256 `id_token`, `/userinfo`, published JWKS with rotation, RFC
|
|
74
|
+
7009 revocation, RFC 9207 `iss`, RFC 8707 audience-bound tokens, and the RFC
|
|
75
|
+
9728 protected-resource metadata an MCP client needs to discover where to
|
|
76
|
+
authorize.
|
|
77
|
+
|
|
78
|
+
Rotating refresh tokens with reuse detection: a replayed authorization code or a
|
|
79
|
+
reused refresh token revokes the entire token family and audits it.
|
|
80
|
+
|
|
81
|
+
## The two things to get right
|
|
82
|
+
|
|
83
|
+
**You write the consent screen.** The package serves a JSON description of the
|
|
84
|
+
pending request at `GET /oauth/consent/:requestId` and takes a decision back at
|
|
85
|
+
`POST`. No markup ships. That payload is a versioned contract with no internal
|
|
86
|
+
ids in it. See the [consent screen
|
|
87
|
+
guide](https://jeffjassky.github.io/oauth-host/guide/consent-screen).
|
|
88
|
+
|
|
89
|
+
**`isAdmin` gates nothing.** There is no admin router — `oauth.clients`,
|
|
90
|
+
`.grants`, `.users` and `.contexts` are plain functions, so there is nothing for
|
|
91
|
+
you to leave unguarded. The moment you put one behind an Express route, the
|
|
92
|
+
guard is yours, and a test asserting a non-admin is refused belongs in your repo.
|
|
93
|
+
|
|
94
|
+
## Non-goals
|
|
95
|
+
|
|
96
|
+
Dynamic client registration (RFC 7591) · admin dashboard · consent screen markup
|
|
97
|
+
· login, sessions, MFA · first-party clients (consent is never skipped) ·
|
|
98
|
+
`client_credentials` · device authorization · token exchange · token
|
|
99
|
+
introspection · JWT access tokens · federation / social login · logout & session
|
|
100
|
+
management · JAR/PAR · OpenID certification. See
|
|
101
|
+
[the full list and the reasoning](https://jeffjassky.github.io/oauth-host/guide/introduction#non-goals).
|
|
102
|
+
|
|
103
|
+
## Requirements
|
|
104
|
+
|
|
105
|
+
Node 20+, Express 4.18+/5, Mongoose 7/8/9. Both are peer dependencies — all
|
|
106
|
+
three Mongoose majors run the full suite in CI.
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm install
|
|
112
|
+
npm run check-tracked # run this FIRST — a global gitignore can eat source files
|
|
113
|
+
npm run typecheck # types/ is hand-written; this is what keeps it honest
|
|
114
|
+
npm run build
|
|
115
|
+
npm test # 148 tests: real HTTP, real Mongo, no mocks
|
|
116
|
+
npm run docs:build # a dead internal link fails this build, on purpose
|
|
117
|
+
|
|
118
|
+
node examples/express/server.js # imports dist/, so build first
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The example boots an in-memory Mongo, registers a client, and prints an
|
|
122
|
+
authorization URL that walks the whole round trip a connector performs.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT © Jeff Jassky
|