authlet 0.1.0-beta.2 → 0.1.0-beta.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 +35 -27
- package/dist/context.d.ts +3 -3
- package/dist/context.js +1 -1
- package/dist/endpoints/authorize.d.ts +1 -1
- package/dist/endpoints/consent.d.ts +2 -2
- package/dist/endpoints/consent.js +1 -1
- package/dist/endpoints/metadata.d.ts +2 -2
- package/dist/endpoints/metadata.js +2 -2
- package/dist/endpoints/register.js +1 -1
- package/dist/endpoints/token.d.ts +1 -1
- package/dist/endpoints/token.js +1 -1
- package/dist/types.d.ts +26 -23
- package/dist/urls.d.ts +3 -3
- package/dist/urls.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
# authlet
|
|
2
2
|
|
|
3
|
-
A small,
|
|
4
|
-
|
|
3
|
+
A small, stateless OAuth 2.1 authorization server built only on Web `Request` and `Response`,
|
|
4
|
+
so it runs on Node, Deno, Bun and edge runtimes. Bring your own users, sessions and tokens.
|
|
5
|
+
|
|
6
|
+
It serves the authorization code flow with PKCE for public clients: dynamic client registration
|
|
7
|
+
(RFC 7591), resource indicators (RFC 8707), protected resource metadata (RFC 9728) and refresh
|
|
8
|
+
token rotation. That is the profile MCP clients use, so an MCP server is the typical host, but
|
|
9
|
+
any API that wants this flow can use it. It has no client credentials or device flow, and no
|
|
10
|
+
OpenID Connect ID tokens.
|
|
5
11
|
|
|
6
12
|
> Status: pre-release, not yet published. `createAuthlet` and all endpoints work, and an
|
|
7
13
|
> end-to-end run with `oauth4webapi` passes. [Planned](#planned) lists what is missing.
|
|
@@ -26,15 +32,15 @@ The app also owns the consent screen. authlet redirects to `consentPage?consent=
|
|
|
26
32
|
`?error=…` for a broken link. The page reads the request with `readConsent`, and its POST handler
|
|
27
33
|
calls `decide`.
|
|
28
34
|
|
|
29
|
-
Access tokens belong to the app too: authlet never validates them. The
|
|
30
|
-
with the app's own auth and calls `challenge(req)` when there is none.
|
|
35
|
+
Access tokens belong to the app too: authlet never validates them. The protected resource checks
|
|
36
|
+
them with the app's own auth and calls `challenge(req)` when there is none.
|
|
31
37
|
|
|
32
|
-
### App-specific
|
|
38
|
+
### App-specific authorization data
|
|
33
39
|
|
|
34
|
-
The consent screen can collect data of its own, such as the
|
|
35
|
-
|
|
36
|
-
[`src/types.test-d.ts`](src/types.test-d.ts) writes this out for
|
|
37
|
-
it, so the example can't drift from the types:
|
|
40
|
+
The consent screen can collect data of its own, such as the capabilities a user allows a client.
|
|
41
|
+
The app's consent POST handler parses and validates it, then passes it to `decide`.
|
|
42
|
+
[`src/types.test-d.ts`](src/types.test-d.ts) writes this out for an MCP server, and `yarn check`
|
|
43
|
+
compiles it, so the example can't drift from the types:
|
|
38
44
|
|
|
39
45
|
```ts
|
|
40
46
|
const authlet = createAuthlet<Capabilities>({/* ... */});
|
|
@@ -47,22 +53,22 @@ export const POST = async (req: Request) => {
|
|
|
47
53
|
return authlet.decide(
|
|
48
54
|
req,
|
|
49
55
|
form.get("decision") === "allow"
|
|
50
|
-
? { consent, allow: true,
|
|
56
|
+
? { consent, allow: true, authorization: parseCapabilities(form) }
|
|
51
57
|
: { consent, allow: false },
|
|
52
58
|
);
|
|
53
59
|
};
|
|
54
60
|
```
|
|
55
61
|
|
|
56
62
|
`decide` checks the request (top-level same-origin form submission, no `Authorization` header,
|
|
57
|
-
same user the consent was shown to) and calls `tokens.issue({ user, client,
|
|
58
|
-
The app stores the
|
|
63
|
+
same user the consent was shown to) and calls `tokens.issue({ user, client, authorization, resource })`.
|
|
64
|
+
The app stores the authorization and returns only a refresh token for it. authlet seals that token into
|
|
59
65
|
an authorization code valid for 60 seconds, plus 5 seconds of clock tolerance. No access token
|
|
60
|
-
exists yet, so none travels through the browser, and the
|
|
66
|
+
exists yet, so none travels through the browser, and the authorization never leaves the server.
|
|
61
67
|
|
|
62
68
|
`issue` may return `null` to refuse a user who lost access since the consent page was shown; the
|
|
63
69
|
browser goes to `consentPage?error=forbidden` and the client gets nothing.
|
|
64
70
|
|
|
65
|
-
Redeeming the code calls `tokens.refresh` with `
|
|
71
|
+
Redeeming the code calls `tokens.refresh` with `grantType: "authorization_code"`, which mints the client's first
|
|
66
72
|
token pair and must refuse a refresh token that was already used. This makes a code single-use
|
|
67
73
|
without authlet storing anything.
|
|
68
74
|
|
|
@@ -73,9 +79,9 @@ two grants for the same client. Both show up in the app's token store.
|
|
|
73
79
|
|
|
74
80
|
authlet can't check these, because they happen in the app:
|
|
75
81
|
|
|
76
|
-
1. Make `
|
|
82
|
+
1. Make `grantType: "authorization_code"` single-use atomically. Mark the refresh token used with a compare-and-set
|
|
77
83
|
(a conditional update rather than a read followed by a write), or two parallel redemptions of
|
|
78
|
-
one code both succeed. Never apply a reuse leeway to `
|
|
84
|
+
one code both succeed. Never apply a reuse leeway to `"authorization_code"`, and revoke the whole token
|
|
79
85
|
family when a used refresh token comes back (RFC 9700 section 4.14).
|
|
80
86
|
2. Treat the consent page as a security boundary:
|
|
81
87
|
- Show the client name as unverified: anyone can register any name.
|
|
@@ -97,25 +103,27 @@ authlet can't check these, because they happen in the app:
|
|
|
97
103
|
## Interface
|
|
98
104
|
|
|
99
105
|
```ts
|
|
100
|
-
//
|
|
101
|
-
const authlet = createAuthlet<Capabilities,
|
|
102
|
-
resource: "https://cms.example.com/api/mcp", // the
|
|
106
|
+
// TAuthorization: what the consent page collects. TUser: the app's user, default { id }.
|
|
107
|
+
const authlet = createAuthlet<Capabilities, AppUser>({
|
|
108
|
+
resource: "https://cms.example.com/api/mcp", // the protected resource, or (req) => string
|
|
103
109
|
issuer: "https://cms.example.com/api/mcp/oauth", // optional, this is the default
|
|
104
|
-
getUser: async (req) => sessionUser(req), //
|
|
110
|
+
getUser: async (req) => sessionUser(req), // AppUser | null
|
|
105
111
|
loginUrl: (returnTo) =>
|
|
106
112
|
`/admin/login?redirect=${encodeURIComponent(returnTo)}`,
|
|
107
113
|
consentPage: "/admin/mcp/authorize", // gets ?consent=… or ?error=…
|
|
108
114
|
secret: process.env.AUTHLET_SECRET!, // >= 32 chars, or an AES-GCM CryptoKey
|
|
109
115
|
tokens: {
|
|
110
|
-
issue: async ({ user, client,
|
|
111
|
-
|
|
116
|
+
issue: async ({ user, client, authorization, resource }) => ({
|
|
117
|
+
refreshToken,
|
|
118
|
+
}), // or null to refuse
|
|
119
|
+
refresh: async ({ refreshToken, grantType, client }) => rotated ?? null, // grantType: "authorization_code" | "refresh_token"
|
|
112
120
|
},
|
|
113
121
|
});
|
|
114
122
|
|
|
115
123
|
authlet.handle(req); // Promise<Response | null>: OAuth endpoints, AS and resource metadata
|
|
116
124
|
authlet.challenge(req); // 401 with WWW-Authenticate: Bearer resource_metadata="..."
|
|
117
|
-
authlet.readConsent(req, consent); // Promise<Consent<
|
|
118
|
-
authlet.decide(req, { consent, allow: true,
|
|
125
|
+
authlet.readConsent(req, consent); // Promise<Consent<AppUser> | null>, for rendering the consent page
|
|
126
|
+
authlet.decide(req, { consent, allow: true, authorization }); // Promise<Response>: redirect with a code
|
|
119
127
|
authlet.decide(req, { consent, allow: false }); // Promise<Response>: redirect with access_denied
|
|
120
128
|
```
|
|
121
129
|
|
|
@@ -132,7 +140,7 @@ The full types are in [`src/types.ts`](src/types.ts).
|
|
|
132
140
|
- `consent.ts`: `readConsent` and `decide`, with `Sec-Fetch-*` checks and `iss` (RFC 9207).
|
|
133
141
|
- `token.ts`: authorization code and refresh grants, single-use codes via refresh rotation.
|
|
134
142
|
- `src/conformance.spec.ts`: the full flow driven by `oauth4webapi` with both discovery styles.
|
|
135
|
-
- `src/types.ts`: the public types; `src/types.test-d.ts`:
|
|
143
|
+
- `src/types.ts`: the public types; `src/types.test-d.ts`: an MCP server's usage, type-checked.
|
|
136
144
|
- `src/seal.ts`: the sealer, typed per sealed value (jose JWE, HKDF-derived key, `typ` and `iss`
|
|
137
145
|
checked on unseal, fixed lifetimes: consent 20 min, code 60 s, each plus 5 s clock tolerance).
|
|
138
146
|
- `src/urls.ts`: issuer and resource canonicalisation, endpoint URLs, and matching a request to
|
|
@@ -156,8 +164,8 @@ With `resource: "https://cms.example.com/api/mcp"` the issuer is
|
|
|
156
164
|
| `/.well-known/openid-configuration/api/mcp/oauth` | AS metadata (OpenID, path inserted) | yes, optional |
|
|
157
165
|
| `/.well-known/oauth-protected-resource/api/mcp` | resource metadata (RFC 9728 default) | yes, optional |
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
first three rows
|
|
167
|
+
Clients that follow `resource_metadata` from the 401 and try the OpenID location below the
|
|
168
|
+
issuer, as MCP clients do, need only the first three rows. Hosts that can serve root paths can forward those requests to
|
|
161
169
|
`handle` as well.
|
|
162
170
|
|
|
163
171
|
Clients check that the issuer and resource in the metadata match exactly. authlet therefore
|
package/dist/context.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { Sealer } from "./seal.js";
|
|
|
2
2
|
import type { AuthletOptions, AuthletUser, AuthorizeError, Resolvable } from "./types.js";
|
|
3
3
|
import type { AuthletUrls } from "./urls.js";
|
|
4
4
|
/** Everything an endpoint needs for one request. */
|
|
5
|
-
interface Context<
|
|
5
|
+
interface Context<TAuthorization, TUser extends AuthletUser> {
|
|
6
6
|
req: Request;
|
|
7
7
|
urls: AuthletUrls;
|
|
8
8
|
sealer: Sealer;
|
|
9
|
-
options: AuthletOptions<
|
|
9
|
+
options: AuthletOptions<TAuthorization, TUser>;
|
|
10
10
|
}
|
|
11
11
|
declare const resolve: <T extends string>(value: Resolvable<T>, req: Request) => T;
|
|
12
12
|
/**
|
|
13
13
|
* The user signed in to this browser. Requests carrying an `Authorization` header never count,
|
|
14
|
-
* or
|
|
14
|
+
* or a client could use its access token to approve a new client for itself.
|
|
15
15
|
*/
|
|
16
16
|
declare const getBrowserUser: <TUser extends AuthletUser>({ req, options, }: {
|
|
17
17
|
req: Request;
|
package/dist/context.js
CHANGED
|
@@ -2,7 +2,7 @@ import { redirect, withParams } from "./http.js";
|
|
|
2
2
|
const resolve = (value, req) => typeof value === "function" ? value(req) : value;
|
|
3
3
|
/**
|
|
4
4
|
* The user signed in to this browser. Requests carrying an `Authorization` header never count,
|
|
5
|
-
* or
|
|
5
|
+
* or a client could use its access token to approve a new client for itself.
|
|
6
6
|
*/
|
|
7
7
|
const getBrowserUser = async ({ req, options, }) => req.headers.has("Authorization") ? null : await options.getUser(req);
|
|
8
8
|
/** Sends the browser to the app's consent page, with a sealed consent or an error. */
|
|
@@ -8,5 +8,5 @@ import type { AuthletUser } from "../types.js";
|
|
|
8
8
|
* redirect URI, so that would turn this endpoint into an open redirector. They go to the
|
|
9
9
|
* consent page with `error=invalid_link` instead.
|
|
10
10
|
*/
|
|
11
|
-
declare const authorize: <
|
|
11
|
+
declare const authorize: <TAuthorization, TUser extends AuthletUser>(ctx: Context<TAuthorization, TUser>) => Promise<Response>;
|
|
12
12
|
export { authorize };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
2
|
import type { AuthletUser, Consent, DecideArgs } from "../types.js";
|
|
3
|
-
declare const readConsent: <
|
|
4
|
-
declare const decide: <
|
|
3
|
+
declare const readConsent: <TAuthorization, TUser extends AuthletUser>(ctx: Context<TAuthorization, TUser>, value: string) => Promise<Consent<TUser> | null>;
|
|
4
|
+
declare const decide: <TAuthorization, TUser extends AuthletUser>(ctx: Context<TAuthorization, TUser>, args: DecideArgs<TAuthorization>) => Promise<Response>;
|
|
5
5
|
export { decide, readConsent };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AuthletUrls } from "../urls.js";
|
|
2
2
|
/**
|
|
3
3
|
* Authorization server metadata (RFC 8414), served at every discovery location. It also
|
|
4
|
-
* carries the fields OpenID discovery requires, since
|
|
4
|
+
* carries the fields OpenID discovery requires, since some clients (MCP among them) read it from
|
|
5
5
|
* `openid-configuration`; no ID tokens are issued.
|
|
6
6
|
*/
|
|
7
7
|
declare const authorizationServerMetadata: (urls: AuthletUrls) => Response;
|
|
8
|
-
/** Protected resource metadata (RFC 9728) for the
|
|
8
|
+
/** Protected resource metadata (RFC 9728) for the resource. */
|
|
9
9
|
declare const resourceMetadata: (urls: AuthletUrls) => Response;
|
|
10
10
|
declare const jwks: () => Response;
|
|
11
11
|
export { authorizationServerMetadata, jwks, resourceMetadata };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { json } from "../http.js";
|
|
2
2
|
/**
|
|
3
3
|
* Authorization server metadata (RFC 8414), served at every discovery location. It also
|
|
4
|
-
* carries the fields OpenID discovery requires, since
|
|
4
|
+
* carries the fields OpenID discovery requires, since some clients (MCP among them) read it from
|
|
5
5
|
* `openid-configuration`; no ID tokens are issued.
|
|
6
6
|
*/
|
|
7
7
|
const authorizationServerMetadata = (urls) => json({
|
|
@@ -18,7 +18,7 @@ const authorizationServerMetadata = (urls) => json({
|
|
|
18
18
|
subject_types_supported: ["public"],
|
|
19
19
|
id_token_signing_alg_values_supported: ["RS256"],
|
|
20
20
|
});
|
|
21
|
-
/** Protected resource metadata (RFC 9728) for the
|
|
21
|
+
/** Protected resource metadata (RFC 9728) for the resource. */
|
|
22
22
|
const resourceMetadata = (urls) => json({
|
|
23
23
|
resource: urls.resource,
|
|
24
24
|
authorization_servers: [urls.issuer],
|
|
@@ -8,7 +8,7 @@ const parseJson = (text) => {
|
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
const DEFAULT_CLIENT_NAME = "An
|
|
11
|
+
const DEFAULT_CLIENT_NAME = "An OAuth client";
|
|
12
12
|
/** Limits that keep the sealed `client_id` short enough to travel in URLs. */
|
|
13
13
|
const MAX_NAME_LENGTH = 100;
|
|
14
14
|
const MAX_REDIRECT_URIS = 10;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
2
|
import type { AuthletUser } from "../types.js";
|
|
3
3
|
/** The token endpoint for public clients: authorization code (PKCE) and refresh token grants. */
|
|
4
|
-
declare const token: <
|
|
4
|
+
declare const token: <TAuthorization, TUser extends AuthletUser>(ctx: Context<TAuthorization, TUser>) => Promise<Response>;
|
|
5
5
|
export { token };
|
package/dist/endpoints/token.js
CHANGED
|
@@ -61,7 +61,7 @@ const token = async (ctx) => {
|
|
|
61
61
|
(await ctx.options.tokens.refresh({
|
|
62
62
|
refreshToken: grant.refreshToken,
|
|
63
63
|
client: { id: clientId },
|
|
64
|
-
|
|
64
|
+
grantType,
|
|
65
65
|
}));
|
|
66
66
|
if (!grant || !tokens) {
|
|
67
67
|
return oauthError("invalid_grant");
|
package/dist/types.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface AuthletClient {
|
|
|
21
21
|
* the code, and redeeming the code rotates it into the client's first token pair, so no access
|
|
22
22
|
* token ever travels through the browser.
|
|
23
23
|
*/
|
|
24
|
-
export interface
|
|
24
|
+
export interface IssuedRefreshToken {
|
|
25
25
|
refreshToken: string;
|
|
26
26
|
}
|
|
27
27
|
/** Tokens created by the app. authlet passes them through and never inspects them. */
|
|
@@ -31,11 +31,14 @@ export interface IssuedTokens {
|
|
|
31
31
|
/** Required, so the next refresh rotates it. Wrapped in a sealed, client-bound value before it reaches the client. */
|
|
32
32
|
refreshToken: string;
|
|
33
33
|
}
|
|
34
|
-
export interface IssueTokensArgs<
|
|
34
|
+
export interface IssueTokensArgs<TAuthorization, TUser extends AuthletUser> {
|
|
35
35
|
user: TUser;
|
|
36
36
|
client: AuthletClient;
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* What the user allowed, as passed to `decide`, such as the capabilities picked on the consent
|
|
39
|
+
* screen. RFC 9396 calls this kind of data authorization details.
|
|
40
|
+
*/
|
|
41
|
+
authorization: TAuthorization;
|
|
39
42
|
/** The protected resource (RFC 8707) the tokens are for. */
|
|
40
43
|
resource: string;
|
|
41
44
|
}
|
|
@@ -43,22 +46,22 @@ export interface RefreshTokensArgs {
|
|
|
43
46
|
refreshToken: string;
|
|
44
47
|
client: Pick<AuthletClient, "id">;
|
|
45
48
|
/**
|
|
46
|
-
*
|
|
47
|
-
* code works once
|
|
48
|
-
* `"
|
|
49
|
+
* The token request's `grant_type`. On `"authorization_code"` the token must never have been
|
|
50
|
+
* used, so the code works once: refuse a second redemption (and revoke the token family). On
|
|
51
|
+
* `"refresh_token"` the app may allow its own reuse leeway.
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
grantType: "authorization_code" | "refresh_token";
|
|
51
54
|
}
|
|
52
55
|
/** Token storage and minting, owned by the app. */
|
|
53
|
-
export interface TokenHooks<
|
|
56
|
+
export interface TokenHooks<TAuthorization, TUser extends AuthletUser> {
|
|
54
57
|
/**
|
|
55
|
-
* Called when the user allows a client: stores the
|
|
58
|
+
* Called when the user allows a client: stores the authorization and returns a refresh token for it,
|
|
56
59
|
* which is sealed into the authorization code. `null` refuses the user (e.g. lost access since
|
|
57
60
|
* the consent page was shown), who is sent to `consentPage?error=forbidden`. Give that refresh
|
|
58
|
-
* token a short lifetime until its first `
|
|
61
|
+
* token a short lifetime until its first `"authorization_code"` rotation, since a code that is never
|
|
59
62
|
* redeemed leaves it unused.
|
|
60
63
|
*/
|
|
61
|
-
issue: (args: IssueTokensArgs<
|
|
64
|
+
issue: (args: IssueTokensArgs<TAuthorization, TUser>) => Promise<IssuedRefreshToken | null>;
|
|
62
65
|
/**
|
|
63
66
|
* Rotates a refresh token into a new token pair, invalidating the old refresh token and any
|
|
64
67
|
* access token issued with it. `null` refuses it. Redeeming a code goes through here too.
|
|
@@ -67,9 +70,9 @@ export interface TokenHooks<TGrant, TUser extends AuthletUser> {
|
|
|
67
70
|
}
|
|
68
71
|
/** Why the authorization request can't be shown to the user. Never sent to the client's redirect URI. */
|
|
69
72
|
export type AuthorizeError = "invalid_link" | "expired" | "forbidden";
|
|
70
|
-
export interface AuthletOptions<
|
|
73
|
+
export interface AuthletOptions<TAuthorization = unknown, TUser extends AuthletUser = AuthletUser> {
|
|
71
74
|
/**
|
|
72
|
-
* The protected resource
|
|
75
|
+
* The protected resource (an API or MCP endpoint URL) in canonical form: absolute https (http only
|
|
73
76
|
* to loopback), no credentials, query, fragment or trailing slash, lowercase host, no default
|
|
74
77
|
* port. Clients compare it exactly, so any other form is refused. Fixed
|
|
75
78
|
* strings are checked at setup, functions on each request. A function must not derive it
|
|
@@ -104,7 +107,7 @@ export interface AuthletOptions<TGrant = unknown, TUser extends AuthletUser = Au
|
|
|
104
107
|
consentPage: Resolvable<string>;
|
|
105
108
|
/** For the built-in AES-GCM sealer: at least 32 characters, or an AES-GCM `CryptoKey`. */
|
|
106
109
|
secret: string | CryptoKey;
|
|
107
|
-
tokens: TokenHooks<
|
|
110
|
+
tokens: TokenHooks<TAuthorization, TUser>;
|
|
108
111
|
}
|
|
109
112
|
/** A pending authorization, as shown on the consent page. */
|
|
110
113
|
export interface Consent<TUser extends AuthletUser = AuthletUser> {
|
|
@@ -114,17 +117,17 @@ export interface Consent<TUser extends AuthletUser = AuthletUser> {
|
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
119
|
* The user's answer on the consent page. `consent` is the sealed consent the page was opened
|
|
117
|
-
* with; `
|
|
120
|
+
* with; `authorization` is what the user allowed, passed to `tokens.issue`.
|
|
118
121
|
*/
|
|
119
|
-
export type DecideArgs<
|
|
122
|
+
export type DecideArgs<TAuthorization> = {
|
|
120
123
|
consent: string;
|
|
121
124
|
allow: true;
|
|
122
|
-
|
|
125
|
+
authorization: TAuthorization;
|
|
123
126
|
} | {
|
|
124
127
|
consent: string;
|
|
125
128
|
allow: false;
|
|
126
129
|
};
|
|
127
|
-
export interface Authlet<
|
|
130
|
+
export interface Authlet<TAuthorization = unknown, TUser extends AuthletUser = AuthletUser> {
|
|
128
131
|
/**
|
|
129
132
|
* Serves the authorization endpoints (`/authorize`, `/token`, `/register`) and the
|
|
130
133
|
* authorization server and protected resource (RFC 9728) metadata. Hosts that route the
|
|
@@ -133,8 +136,8 @@ export interface Authlet<TGrant = unknown, TUser extends AuthletUser = AuthletUs
|
|
|
133
136
|
*/
|
|
134
137
|
handle: (req: Request) => Promise<Response | null>;
|
|
135
138
|
/**
|
|
136
|
-
* The 401 for
|
|
137
|
-
* issuer, which
|
|
139
|
+
* The 401 for a request to the resource without a valid token. Its `resource_metadata` points
|
|
140
|
+
* below the issuer, which RFC 9728 clients follow, so discovery works under a base path.
|
|
138
141
|
*/
|
|
139
142
|
challenge: (req: Request) => Response;
|
|
140
143
|
/** The pending authorization behind a sealed consent, or `null` if it's invalid, expired or for another user. */
|
|
@@ -146,6 +149,6 @@ export interface Authlet<TGrant = unknown, TUser extends AuthletUser = AuthletUs
|
|
|
146
149
|
* submission (`Sec-Fetch-Dest`, `Sec-Fetch-Site`, or `Origin` in older browsers), carry an
|
|
147
150
|
* `Authorization` header, or come from another user than the one the consent was shown to.
|
|
148
151
|
*/
|
|
149
|
-
decide: (req: Request, args: DecideArgs<
|
|
152
|
+
decide: (req: Request, args: DecideArgs<TAuthorization>) => Promise<Response>;
|
|
150
153
|
}
|
|
151
|
-
export type CreateAuthlet = <
|
|
154
|
+
export type CreateAuthlet = <TAuthorization = unknown, TUser extends AuthletUser = AuthletUser>(options: AuthletOptions<TAuthorization, TUser>) => Authlet<TAuthorization, TUser>;
|
package/dist/urls.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ interface AuthletUrls {
|
|
|
9
9
|
jwksUri: string;
|
|
10
10
|
/**
|
|
11
11
|
* The protected resource metadata (RFC 9728) that `challenge` points to. It sits below the
|
|
12
|
-
* issuer, so a host mounted under a base path needs no route at the site root:
|
|
13
|
-
* must
|
|
12
|
+
* issuer, so a host mounted under a base path needs no route at the site root: clients
|
|
13
|
+
* following RFC 9728 (MCP clients must) read `resource_metadata` from the challenge.
|
|
14
14
|
*/
|
|
15
15
|
resourceMetadata: string;
|
|
16
16
|
}
|
|
@@ -23,7 +23,7 @@ declare const deriveUrls: (args: {
|
|
|
23
23
|
/**
|
|
24
24
|
* Which endpoint a request URL addresses, or `null`. Only the path is compared, because behind
|
|
25
25
|
* a TLS-terminating proxy the request URL can carry another scheme or host than the public one.
|
|
26
|
-
* Metadata answers at every location
|
|
26
|
+
* Metadata answers at every location clients try: path-appended OpenID discovery below
|
|
27
27
|
* the issuer, which needs no root route, and the root-level well-known paths for hosts that
|
|
28
28
|
* route them here.
|
|
29
29
|
*/
|
package/dist/urls.js
CHANGED
|
@@ -39,7 +39,7 @@ const insertWellKnown = (url, wellKnown) => {
|
|
|
39
39
|
/**
|
|
40
40
|
* Which endpoint a request URL addresses, or `null`. Only the path is compared, because behind
|
|
41
41
|
* a TLS-terminating proxy the request URL can carry another scheme or host than the public one.
|
|
42
|
-
* Metadata answers at every location
|
|
42
|
+
* Metadata answers at every location clients try: path-appended OpenID discovery below
|
|
43
43
|
* the issuer, which needs no root route, and the root-level well-known paths for hosts that
|
|
44
44
|
* route them here.
|
|
45
45
|
*/
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "authlet",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.1.0-beta.3",
|
|
5
|
+
"description": "Stateless, runtime-agnostic OAuth 2.1 authorization server built on Web Request and Response.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"oauth",
|
|
8
8
|
"oauth2",
|