@mcpfn/auth 0.0.1 → 0.0.3
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 +57 -3
- package/dist/index.cjs +1816 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +371 -1
- package/dist/index.d.ts +371 -1
- package/dist/index.js +1800 -36
- package/dist/index.js.map +1 -1
- package/package.json +15 -5
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# `@mcpfn/auth`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
It publishes RFC 9728 protected-resource metadata, validates Bearer tokens through the official SDK's `OAuthTokenVerifier` contract, enforces token expiry, resource indicators, and scopes, and passes trusted `authInfo` into the McpFn HTTP transport. Authorization-code, PKCE, DCR, and token issuance remain the authorization server's responsibility.
|
|
3
|
+
OAuth integration for MCP clients, resource servers, and hosted authorization
|
|
4
|
+
systems. Protocol mechanics remain in the official MCP SDK.
|
|
6
5
|
|
|
7
6
|
```ts
|
|
8
7
|
import { createOAuthResourceServerHandler } from "@mcpfn/auth";
|
|
@@ -18,3 +17,58 @@ const fetch = createOAuthResourceServerHandler(mcp, {
|
|
|
18
17
|
```
|
|
19
18
|
|
|
20
19
|
Enterprise-managed authorization helpers advertise the stable ID-JAG grant profile in authorization-server metadata and build the request metadata used by supporting clients.
|
|
20
|
+
|
|
21
|
+
## Client provider
|
|
22
|
+
|
|
23
|
+
`createMcpFnOAuthClientProvider()` implements the official
|
|
24
|
+
`OAuthClientProvider`. It validates the requested redirect against registered
|
|
25
|
+
metadata before opening a browser, correlates callback state, stores PKCE and
|
|
26
|
+
tokens in memory unless an encrypted store is supplied, classifies token
|
|
27
|
+
exchange/refresh/revocation diagnostics, and redacts credentials.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
const provider = createMcpFnOAuthClientProvider({
|
|
31
|
+
redirectUrl: "http://127.0.0.1/callback",
|
|
32
|
+
clientMetadata: {
|
|
33
|
+
redirect_uris: ["http://127.0.0.1/callback"],
|
|
34
|
+
response_types: ["code"],
|
|
35
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
36
|
+
},
|
|
37
|
+
openAuthorization: (url) => browser.open(url),
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Pass it to `streamableHttpTarget`. Complete interactive authorization with
|
|
42
|
+
`client.completeAuthorization({ code, state })`; a missing or mismatched state
|
|
43
|
+
fails before token exchange. Dynamic loopback ports are accepted only when the
|
|
44
|
+
registered URI omits the port. Other redirect URIs require exact equality.
|
|
45
|
+
|
|
46
|
+
## Hosted compatibility
|
|
47
|
+
|
|
48
|
+
`createMcpAuthorizationCompatibilityHandler()` publishes authorization-server
|
|
49
|
+
metadata and composes DCR, pre-registration, Client ID Metadata Documents,
|
|
50
|
+
authorization-code + PKCE request validation, typed token exchange, serialized
|
|
51
|
+
refresh rotation, and revocation endpoints. Metadata is derived from the token
|
|
52
|
+
authority callbacks and declared client-auth methods, so unsupported grants or
|
|
53
|
+
methods are never advertised. McpFn parses and validates endpoint requests;
|
|
54
|
+
the host application's callbacks remain authoritative for login, consent,
|
|
55
|
+
durable clients, code issuance, signing, token values, and revocation state.
|
|
56
|
+
External Client ID Metadata Documents require an explicit URL allow-policy.
|
|
57
|
+
McpFn disables automatic redirects, reapplies that policy at every redirect,
|
|
58
|
+
streams responses through a byte cap, and applies a ten-second deadline by
|
|
59
|
+
default. `maxBytes`, `timeoutMs`, and `maxRedirects` can tighten those bounds.
|
|
60
|
+
|
|
61
|
+
The AuthFn adapter uses a structural provider contract. `@superfunctions/auth`
|
|
62
|
+
is an optional peer: installing or importing AuthFn is not required for other
|
|
63
|
+
client, resource-server, or hosted authorization features.
|
|
64
|
+
|
|
65
|
+
`createMcpFnAuthProviderAdapter()` maps a generic `@superfunctions/auth`
|
|
66
|
+
session into official MCP `authInfo`, keeping identity, tenant, scopes, and
|
|
67
|
+
resources out of model-controlled tool arguments. Bearer credentials are
|
|
68
|
+
required. A bearer-specific provider can implement
|
|
69
|
+
`authenticateBearer(token, request)` directly; a standard AuthFn
|
|
70
|
+
`authenticate(request)` provider is invoked with a credential-isolated request
|
|
71
|
+
containing only that exact Bearer token. An AuthProvider's `authorize()` hook
|
|
72
|
+
receives the normalized MCP resource URL before trusted context is created. `auth-diagnose` and
|
|
73
|
+
`diagnoseMcpAuthorization()` perform read-only discovery without browser or
|
|
74
|
+
credential actions.
|