@pexis/auth 0.1.2 → 0.1.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 +1 -1
- package/api.json +2188 -0
- package/dist/index.d.ts +56 -5
- package/dist/index.js +49 -5
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +65 -2
- package/dist/jwt.js +45 -2
- package/dist/jwt.js.map +1 -1
- package/dist/providers.d.ts +72 -1
- package/dist/providers.js +37 -1
- package/dist/providers.js.map +1 -1
- package/dist/server/client.d.ts +69 -6
- package/dist/server/client.js +41 -5
- package/dist/server/client.js.map +1 -1
- package/dist/server/plugin.d.ts +23 -1
- package/dist/server/plugin.js +17 -1
- package/dist/server/plugin.js.map +1 -1
- package/dist/server/store.d.ts +64 -5
- package/dist/server/store.js +14 -2
- package/dist/server/store.js.map +1 -1
- package/package.json +5 -4
package/dist/providers.d.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import { type Claims } from './jwt.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a provider's token endpoint answered, as OAuth names it.
|
|
4
|
+
*
|
|
5
|
+
* @category plugins
|
|
6
|
+
*/
|
|
2
7
|
export interface TokenResponse {
|
|
8
|
+
/** The access token, for calling the provider's API. Never logged. */
|
|
3
9
|
access_token?: string;
|
|
10
|
+
/** The OpenID Connect ID token, verified before use. */
|
|
4
11
|
id_token?: string;
|
|
12
|
+
/** Usually "Bearer". */
|
|
5
13
|
token_type?: string;
|
|
14
|
+
/** Seconds until the access token expires. */
|
|
6
15
|
expires_in?: number;
|
|
16
|
+
/** The scopes granted, space-separated. */
|
|
7
17
|
scope?: string;
|
|
18
|
+
/** Any other fields the provider sent. */
|
|
8
19
|
[key: string]: unknown;
|
|
9
20
|
}
|
|
10
21
|
/** What a provider tells us about the person. */
|
|
11
22
|
export interface Profile {
|
|
12
23
|
/** The provider's stable ID for the person. */
|
|
13
24
|
subject: string;
|
|
25
|
+
/** Their email address, if the provider shared it. */
|
|
14
26
|
email?: string;
|
|
15
27
|
/** Whether the provider verified the email. Never link accounts by an unverified email. */
|
|
16
28
|
emailVerified: boolean;
|
|
29
|
+
/** Their display name. */
|
|
17
30
|
name?: string;
|
|
31
|
+
/** An https URL of their picture. */
|
|
18
32
|
picture?: string;
|
|
19
33
|
}
|
|
20
34
|
export interface ProfileInput {
|
|
@@ -24,20 +38,32 @@ export interface ProfileInput {
|
|
|
24
38
|
/** Extra fields a form_post provider sent with the callback (Apple's "user"). Untrusted. */
|
|
25
39
|
form?: Record<string, string>;
|
|
26
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A sign-in provider, from google(), microsoft(), github(), apple() or oidc():
|
|
43
|
+
* a few facts about the provider and how to read its answer.
|
|
44
|
+
*
|
|
45
|
+
* @category plugins
|
|
46
|
+
*/
|
|
27
47
|
export interface Provider {
|
|
48
|
+
/** The provider's id, in sign-in URLs: /auth/<id>. */
|
|
28
49
|
id: string;
|
|
29
50
|
/** Shown on the sign-in button: "Continue with <name>". */
|
|
30
51
|
name: string;
|
|
52
|
+
/** Your app's client id at the provider. */
|
|
31
53
|
clientId: string;
|
|
32
54
|
/** A fixed secret, or a function for providers whose secret is a short-lived token (Apple). */
|
|
33
55
|
clientSecret?: string | (() => Promise<string>);
|
|
56
|
+
/** The scopes asked for. */
|
|
34
57
|
scopes: string[];
|
|
35
58
|
/** OpenID Connect issuer. Set this, or the endpoints below. */
|
|
36
59
|
issuer?: string;
|
|
37
60
|
/** For providers whose issuer varies, such as Microsoft's multi-tenant endpoint. */
|
|
38
61
|
issuerCheck?: (iss: string, claims: Claims) => boolean;
|
|
62
|
+
/** Where people are sent to sign in, when there is no issuer to discover it from. */
|
|
39
63
|
authorizationEndpoint?: string;
|
|
64
|
+
/** Where the code is exchanged for tokens, when there is no issuer. */
|
|
40
65
|
tokenEndpoint?: string;
|
|
66
|
+
/** Where the provider's signing keys are, when there is no issuer. */
|
|
41
67
|
jwksUri?: string;
|
|
42
68
|
/** Whether the provider returns an ID token to verify. */
|
|
43
69
|
oidc: boolean;
|
|
@@ -45,7 +71,9 @@ export interface Provider {
|
|
|
45
71
|
responseMode?: 'query' | 'form_post';
|
|
46
72
|
/** Extra parameters for the authorization request, such as prompt. */
|
|
47
73
|
authorizationParams?: Record<string, string>;
|
|
74
|
+
/** How the client secret is sent to the token endpoint: in the body, or as HTTP Basic. */
|
|
48
75
|
tokenAuth?: 'post' | 'basic';
|
|
76
|
+
/** Reads the person's profile from the verified ID token, or from the provider's API. */
|
|
49
77
|
profile(input: ProfileInput): Promise<Profile>;
|
|
50
78
|
}
|
|
51
79
|
interface Credentials {
|
|
@@ -55,27 +83,70 @@ interface Credentials {
|
|
|
55
83
|
scopes?: string[];
|
|
56
84
|
authorizationParams?: Record<string, string>;
|
|
57
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign in with Google (OpenID Connect).
|
|
88
|
+
*
|
|
89
|
+
* @param options Your client id and secret from the Google Cloud console, and extra scopes.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* google({ clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET! })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
58
95
|
export declare function google(options: Credentials): Provider;
|
|
96
|
+
/**
|
|
97
|
+
* Sign in with Microsoft: work, school and personal accounts (OpenID Connect).
|
|
98
|
+
* Microsoft does not promise emails are verified, so they are never marked so.
|
|
99
|
+
*
|
|
100
|
+
* @param options Your client id and secret, and `tenant`: "common" (default), "organizations", "consumers" or a tenant id.
|
|
101
|
+
*/
|
|
59
102
|
export declare function microsoft(options: Credentials & {
|
|
60
103
|
tenant?: string;
|
|
61
104
|
}): Provider;
|
|
105
|
+
/**
|
|
106
|
+
* Sign in with GitHub (OAuth). The profile comes from GitHub's API, with the
|
|
107
|
+
* primary verified email.
|
|
108
|
+
*
|
|
109
|
+
* @param options Your OAuth app's client id and secret, and extra scopes.
|
|
110
|
+
*/
|
|
62
111
|
export declare function github(options: Credentials): Provider;
|
|
112
|
+
/** What apple() takes, from the Apple Developer account. */
|
|
63
113
|
export interface AppleOptions {
|
|
64
114
|
/** The Services ID. */
|
|
65
115
|
clientId: string;
|
|
116
|
+
/** Your Apple Developer team id. */
|
|
66
117
|
teamId: string;
|
|
118
|
+
/** The id of the Sign in with Apple key. */
|
|
67
119
|
keyId: string;
|
|
68
120
|
/** The .p8 private key, as PEM text. Read it from a secret, never commit it. */
|
|
69
121
|
privateKey: string;
|
|
70
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Sign in with Apple (OpenID Connect). The client secret is a short-lived
|
|
125
|
+
* token signed with your key, made for you. Apple posts the callback as a
|
|
126
|
+
* form, which Pexis lets past CSRF from appleid.apple.com only.
|
|
127
|
+
*
|
|
128
|
+
* @param options Your Services ID, team id, key id and private key.
|
|
129
|
+
*/
|
|
71
130
|
export declare function apple(options: AppleOptions): Provider;
|
|
131
|
+
/** What oidc() takes. */
|
|
72
132
|
export interface OidcOptions extends Credentials {
|
|
133
|
+
/** The provider's id, in sign-in URLs: lowercase letters, digits and hyphens. */
|
|
73
134
|
id: string;
|
|
135
|
+
/** Shown on the sign-in button: "Continue with <name>". */
|
|
74
136
|
name: string;
|
|
137
|
+
/** The issuer URL; its endpoints are read from /.well-known/openid-configuration. */
|
|
75
138
|
issuer: string;
|
|
76
139
|
/** Default ["openid", "email", "profile"]. */
|
|
77
140
|
scopes?: string[];
|
|
78
141
|
}
|
|
79
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* Any OpenID Connect provider: Okta, Auth0, Keycloak, Entra ID, Cognito, GitLab and others.
|
|
144
|
+
*
|
|
145
|
+
* @param options Its id, name, issuer, and your client id and secret.
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* oidc({ id: 'okta', name: 'Okta', issuer: 'https://dev-123.okta.com', clientId: '...', clientSecret: process.env.OKTA_SECRET! })
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
80
151
|
export declare function oidc(options: OidcOptions): Provider;
|
|
81
152
|
export {};
|
package/dist/providers.js
CHANGED
|
@@ -19,6 +19,15 @@ function claimsProfile(claims) {
|
|
|
19
19
|
profile.picture = picture;
|
|
20
20
|
return profile;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Sign in with Google (OpenID Connect).
|
|
24
|
+
*
|
|
25
|
+
* @param options Your client id and secret from the Google Cloud console, and extra scopes.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* google({ clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET! })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
22
31
|
export function google(options) {
|
|
23
32
|
return {
|
|
24
33
|
id: 'google',
|
|
@@ -34,6 +43,12 @@ export function google(options) {
|
|
|
34
43
|
profile: async ({ claims }) => claimsProfile(claims),
|
|
35
44
|
};
|
|
36
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Sign in with Microsoft: work, school and personal accounts (OpenID Connect).
|
|
48
|
+
* Microsoft does not promise emails are verified, so they are never marked so.
|
|
49
|
+
*
|
|
50
|
+
* @param options Your client id and secret, and `tenant`: "common" (default), "organizations", "consumers" or a tenant id.
|
|
51
|
+
*/
|
|
37
52
|
export function microsoft(options) {
|
|
38
53
|
const tenant = (options.tenant ?? 'common').toLowerCase();
|
|
39
54
|
const multi = ['common', 'organizations', 'consumers'].includes(tenant);
|
|
@@ -63,6 +78,12 @@ export function microsoft(options) {
|
|
|
63
78
|
},
|
|
64
79
|
};
|
|
65
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Sign in with GitHub (OAuth). The profile comes from GitHub's API, with the
|
|
83
|
+
* primary verified email.
|
|
84
|
+
*
|
|
85
|
+
* @param options Your OAuth app's client id and secret, and extra scopes.
|
|
86
|
+
*/
|
|
66
87
|
export function github(options) {
|
|
67
88
|
return {
|
|
68
89
|
id: 'github',
|
|
@@ -103,6 +124,13 @@ export function github(options) {
|
|
|
103
124
|
},
|
|
104
125
|
};
|
|
105
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Sign in with Apple (OpenID Connect). The client secret is a short-lived
|
|
129
|
+
* token signed with your key, made for you. Apple posts the callback as a
|
|
130
|
+
* form, which Pexis lets past CSRF from appleid.apple.com only.
|
|
131
|
+
*
|
|
132
|
+
* @param options Your Services ID, team id, key id and private key.
|
|
133
|
+
*/
|
|
106
134
|
export function apple(options) {
|
|
107
135
|
let cached;
|
|
108
136
|
return {
|
|
@@ -143,7 +171,15 @@ export function apple(options) {
|
|
|
143
171
|
},
|
|
144
172
|
};
|
|
145
173
|
}
|
|
146
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Any OpenID Connect provider: Okta, Auth0, Keycloak, Entra ID, Cognito, GitLab and others.
|
|
176
|
+
*
|
|
177
|
+
* @param options Its id, name, issuer, and your client id and secret.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* oidc({ id: 'okta', name: 'Okta', issuer: 'https://dev-123.okta.com', clientId: '...', clientSecret: process.env.OKTA_SECRET! })
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
147
183
|
export function oidc(options) {
|
|
148
184
|
if (!/^[a-z][a-z0-9-]{0,31}$/.test(options.id))
|
|
149
185
|
throw new Error('oidc(): id must be lowercase letters, digits and hyphens.');
|
package/dist/providers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,SAAS,EAAe,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,SAAS,EAAe,MAAM,UAAU,CAA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AE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC7H,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;QACxD,qEAAqE;QACrE,2DAA2D;QAC3D,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,IAAI;QACV,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5F,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;KACrD,CAAC;AACJ,CAAC"}
|
package/dist/server/client.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* What the loader's fetch returns.
|
|
3
|
+
*
|
|
4
|
+
* @experimental
|
|
5
|
+
*/
|
|
2
6
|
export interface MetadataResponse {
|
|
7
|
+
/** The HTTP status. */
|
|
3
8
|
status: number;
|
|
9
|
+
/** The response headers. */
|
|
4
10
|
headers: Headers;
|
|
11
|
+
/** The body, at most maxBytes. */
|
|
5
12
|
body: Uint8Array;
|
|
6
13
|
}
|
|
7
14
|
/**
|
|
@@ -9,30 +16,75 @@ export interface MetadataResponse {
|
|
|
9
16
|
* and when the signal aborts. publicFetch from @pexis/node/public-fetch also
|
|
10
17
|
* refuses names that resolve to non-public addresses; the default (web fetch)
|
|
11
18
|
* cannot see addresses, so it is accepted only for clients the app lists.
|
|
19
|
+
*
|
|
20
|
+
* @experimental
|
|
12
21
|
*/
|
|
13
22
|
export type MetadataFetch = (url: URL, options: {
|
|
14
23
|
signal: AbortSignal;
|
|
15
24
|
maxBytes: number;
|
|
16
25
|
}) => Promise<MetadataResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* An OAuth client, from its Client ID Metadata Document.
|
|
28
|
+
*
|
|
29
|
+
* @experimental
|
|
30
|
+
*/
|
|
17
31
|
export interface ClientMetadata {
|
|
32
|
+
/** The client's id: the URL of its metadata document. */
|
|
18
33
|
clientId: string;
|
|
19
34
|
/** What the client calls itself. Untrusted text: show it escaped, never as the client's identity. */
|
|
20
35
|
name: string;
|
|
36
|
+
/** Where codes may be sent, as the document lists them. */
|
|
21
37
|
redirectUris: string[];
|
|
22
38
|
}
|
|
23
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* A client that cannot be used, with a reason safe to show the person.
|
|
41
|
+
*
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
24
44
|
export declare class ClientError extends Error {
|
|
25
45
|
}
|
|
26
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* The client_id as a URL, or a ClientError saying why it cannot be one.
|
|
48
|
+
*
|
|
49
|
+
* @experimental
|
|
50
|
+
* @param raw The client_id as sent.
|
|
51
|
+
*/
|
|
27
52
|
export declare function clientIdUrl(raw: string): URL;
|
|
28
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* A redirect URI a client may list: https, or http on a loopback address for
|
|
55
|
+
* apps on the person's computer (RFC 8252). Throws ClientError otherwise.
|
|
56
|
+
*
|
|
57
|
+
* @experimental
|
|
58
|
+
* @param raw The redirect URI as listed.
|
|
59
|
+
*/
|
|
29
60
|
export declare function checkRedirectUri(raw: string): URL;
|
|
61
|
+
/**
|
|
62
|
+
* Whether a URL is http on a loopback address: an app on the person's own computer.
|
|
63
|
+
*
|
|
64
|
+
* @experimental
|
|
65
|
+
*/
|
|
30
66
|
export declare const isLoopback: (url: URL) => boolean;
|
|
31
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Whether a requested redirect URI is one the client listed: exact, except the port of a loopback URI (RFC 8252 §7.3).
|
|
69
|
+
*
|
|
70
|
+
* @experimental
|
|
71
|
+
* @param client The client.
|
|
72
|
+
* @param requested The redirect URI in the request.
|
|
73
|
+
*/
|
|
32
74
|
export declare function redirectAllowed(client: ClientMetadata, requested: string): boolean;
|
|
33
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Web fetch, for clients the app lists by name. No redirects, a byte limit counted after decompression.
|
|
77
|
+
*
|
|
78
|
+
* @experimental
|
|
79
|
+
*/
|
|
34
80
|
export declare const webMetadataFetch: MetadataFetch;
|
|
81
|
+
/**
|
|
82
|
+
* What clientLoader() takes.
|
|
83
|
+
*
|
|
84
|
+
* @experimental
|
|
85
|
+
*/
|
|
35
86
|
export interface ClientLoaderOptions {
|
|
87
|
+
/** How metadata documents are fetched. */
|
|
36
88
|
fetch: MetadataFetch;
|
|
37
89
|
/** Cached clients and failures, at most. Default 1000. */
|
|
38
90
|
maxEntries?: number;
|
|
@@ -41,8 +93,19 @@ export interface ClientLoaderOptions {
|
|
|
41
93
|
/** Fetches running at once to one host. Default 2. */
|
|
42
94
|
perHost?: number;
|
|
43
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Loads and caches client metadata, with limits on fetches at once.
|
|
98
|
+
*
|
|
99
|
+
* @experimental
|
|
100
|
+
*/
|
|
44
101
|
export interface ClientLoader {
|
|
45
102
|
/** The client, from the cache or fetched. Throws ClientError. */
|
|
46
103
|
load(clientId: string): Promise<ClientMetadata>;
|
|
47
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* A cached, rate-limited loader of client metadata documents.
|
|
107
|
+
*
|
|
108
|
+
* @experimental
|
|
109
|
+
* @param options The fetch, and cache and concurrency limits.
|
|
110
|
+
*/
|
|
48
111
|
export declare function clientLoader(options: ClientLoaderOptions): ClientLoader;
|
package/dist/server/client.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// an https URL, and the document there names the client and where codes may
|
|
3
3
|
// be sent. Fetching a URL someone else chose is a server-side request forgery
|
|
4
4
|
// risk, so every rule here is about what may be fetched and what is believed.
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* A client that cannot be used, with a reason safe to show the person.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
6
10
|
export class ClientError extends Error {
|
|
7
11
|
}
|
|
8
12
|
const MAX_BYTES = 10 * 1024;
|
|
@@ -12,7 +16,12 @@ const MAX_CACHE_S = 24 * 60 * 60;
|
|
|
12
16
|
const FAILURE_CACHE_S = 60;
|
|
13
17
|
const BLOCKED_SUFFIXES = ['localhost', 'local', 'internal', 'test', 'lan', 'corp', 'home.arpa', 'svc', 'example', 'invalid', 'onion'];
|
|
14
18
|
const isIpHost = (host) => host.startsWith('[') || /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The client_id as a URL, or a ClientError saying why it cannot be one.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
* @param raw The client_id as sent.
|
|
24
|
+
*/
|
|
16
25
|
export function clientIdUrl(raw) {
|
|
17
26
|
let url;
|
|
18
27
|
try {
|
|
@@ -48,7 +57,13 @@ export function clientIdUrl(raw) {
|
|
|
48
57
|
// the other address at the same port could receive the code (RFC 8252 §8.3);
|
|
49
58
|
// PKCE makes a code useless without the client's verifier.
|
|
50
59
|
const LOOPBACK_HOSTS = new Set(['127.0.0.1', '[::1]', 'localhost']);
|
|
51
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* A redirect URI a client may list: https, or http on a loopback address for
|
|
62
|
+
* apps on the person's computer (RFC 8252). Throws ClientError otherwise.
|
|
63
|
+
*
|
|
64
|
+
* @experimental
|
|
65
|
+
* @param raw The redirect URI as listed.
|
|
66
|
+
*/
|
|
52
67
|
export function checkRedirectUri(raw) {
|
|
53
68
|
let url;
|
|
54
69
|
try {
|
|
@@ -65,8 +80,19 @@ export function checkRedirectUri(raw) {
|
|
|
65
80
|
return url;
|
|
66
81
|
throw new ClientError('A redirect URI must be https, or http on localhost, 127.0.0.1 or [::1].');
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether a URL is http on a loopback address: an app on the person's own computer.
|
|
85
|
+
*
|
|
86
|
+
* @experimental
|
|
87
|
+
*/
|
|
68
88
|
export const isLoopback = (url) => url.protocol === 'http:' && LOOPBACK_HOSTS.has(url.hostname);
|
|
69
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Whether a requested redirect URI is one the client listed: exact, except the port of a loopback URI (RFC 8252 §7.3).
|
|
91
|
+
*
|
|
92
|
+
* @experimental
|
|
93
|
+
* @param client The client.
|
|
94
|
+
* @param requested The redirect URI in the request.
|
|
95
|
+
*/
|
|
70
96
|
export function redirectAllowed(client, requested) {
|
|
71
97
|
let want;
|
|
72
98
|
try {
|
|
@@ -84,7 +110,11 @@ export function redirectAllowed(client, requested) {
|
|
|
84
110
|
return have.hostname === want.hostname && have.pathname === want.pathname && have.search === want.search;
|
|
85
111
|
});
|
|
86
112
|
}
|
|
87
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Web fetch, for clients the app lists by name. No redirects, a byte limit counted after decompression.
|
|
115
|
+
*
|
|
116
|
+
* @experimental
|
|
117
|
+
*/
|
|
88
118
|
export const webMetadataFetch = async (url, { signal, maxBytes }) => {
|
|
89
119
|
const res = await fetch(url, { redirect: 'error', signal, credentials: 'omit', headers: { accept: 'application/json' } });
|
|
90
120
|
const reader = res.body?.getReader();
|
|
@@ -145,6 +175,12 @@ function parse(clientId, response) {
|
|
|
145
175
|
checkRedirectUri(uri);
|
|
146
176
|
return { clientId, name: d.client_name.trim(), redirectUris: [...d.redirect_uris] };
|
|
147
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* A cached, rate-limited loader of client metadata documents.
|
|
180
|
+
*
|
|
181
|
+
* @experimental
|
|
182
|
+
* @param options The fetch, and cache and concurrency limits.
|
|
183
|
+
*/
|
|
148
184
|
export function clientLoader(options) {
|
|
149
185
|
const maxEntries = options.maxEntries ?? 1000;
|
|
150
186
|
const concurrency = options.concurrency ?? 8;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/server/client.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/server/client.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAwC9E;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;CAAG;AAEzC,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,CAAC;AAC3B,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACjC,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAEtI,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhG;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,WAAW,CAAC,6BAA6B,CAA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,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACnC,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;gBACxC,IAAI,MAAM,CAAC,MAAM;oBAAE,OAAO,MAAM,CAAC,MAAM,CAAC;gBACxC,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,IAAI,+BAA+B,CAAC,CAAC;YACzE,CAAC;YACD,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvC,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;YAC5B,MAAM,OAAO,GAAG,WAAW,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YACpF,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -2,7 +2,18 @@ import { type Plugin } from '@pexis/core';
|
|
|
2
2
|
import { type User } from '@pexis/sessions';
|
|
3
3
|
import { type MetadataFetch } from './client.js';
|
|
4
4
|
import { type OAuthStore } from './store.js';
|
|
5
|
+
/**
|
|
6
|
+
* The scopes a person can grant a client: "actions:read" to look things up,
|
|
7
|
+
* "actions:write" to make changes (which includes reading).
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*/
|
|
5
11
|
export declare const SCOPES: readonly ['actions:read', 'actions:write'];
|
|
12
|
+
/**
|
|
13
|
+
* What oauthServer() takes.
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
6
17
|
export interface OAuthServerOptions {
|
|
7
18
|
/**
|
|
8
19
|
* The person a grant acts for, looked up again on every request (cached for
|
|
@@ -18,6 +29,7 @@ export interface OAuthServerOptions {
|
|
|
18
29
|
clients: readonly string[] | 'any';
|
|
19
30
|
/** How client metadata is fetched. Default: web fetch, allowed only with a list of clients. */
|
|
20
31
|
fetchMetadata?: MetadataFetch;
|
|
32
|
+
/** Where grants and tokens are kept. Default: memoryOAuthStore(), one server only; use oauthStore(db) from @pexis/data. */
|
|
21
33
|
store?: OAuthStore;
|
|
22
34
|
/** Days a grant lasts at most. Default 30; loopback clients (apps on the person's computer) get at most 7. */
|
|
23
35
|
grantDays?: number;
|
|
@@ -26,12 +38,22 @@ export interface OAuthServerOptions {
|
|
|
26
38
|
/** The MCP endpoint the tokens are for. Default "/pexis/mcp". */
|
|
27
39
|
resourcePath?: string;
|
|
28
40
|
}
|
|
29
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The Bearer token in an Authorization header, or null. Other schemes (Basic) are not ours.
|
|
43
|
+
*
|
|
44
|
+
* @experimental
|
|
45
|
+
* @param request The request.
|
|
46
|
+
*/
|
|
30
47
|
export declare function bearerToken(request: Request): string | null;
|
|
31
48
|
/**
|
|
32
49
|
* Lets MCP clients sign in as a person with OAuth 2.1, so they can call
|
|
33
50
|
* actions that need a permission. Needs sessions() and auth().
|
|
34
51
|
*
|
|
35
52
|
* @experimental Still being designed: may change, or go, without a deprecation period.
|
|
53
|
+
* @param options How users are loaded, which clients may sign in, and where grants are kept.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* oauthServer({ loadUser: (id) => findUser(db, id), clients: ['https://claude.ai/oauth/mcp-client'], store: oauthStore(db) })
|
|
57
|
+
* ```
|
|
36
58
|
*/
|
|
37
59
|
export declare function oauthServer(options: OAuthServerOptions): Plugin;
|
package/dist/server/plugin.js
CHANGED
|
@@ -16,6 +16,12 @@ import { signedInWithin } from '@pexis/sessions';
|
|
|
16
16
|
import { requireRecentSignIn, requireUser } from '../index.js';
|
|
17
17
|
import { ClientError, clientIdUrl, clientLoader, isLoopback, redirectAllowed, webMetadataFetch } from './client.js';
|
|
18
18
|
import { hashSecret, memoryOAuthStore, newSecret } from './store.js';
|
|
19
|
+
/**
|
|
20
|
+
* The scopes a person can grant a client: "actions:read" to look things up,
|
|
21
|
+
* "actions:write" to make changes (which includes reading).
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
19
25
|
export const SCOPES = ['actions:read', 'actions:write'];
|
|
20
26
|
const SCOPE_TEXT = {
|
|
21
27
|
'actions:read': 'Look things up on this site as you (searches and other actions that change nothing).',
|
|
@@ -45,7 +51,12 @@ function same(a, b) {
|
|
|
45
51
|
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
46
52
|
return diff === 0;
|
|
47
53
|
}
|
|
48
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The Bearer token in an Authorization header, or null. Other schemes (Basic) are not ours.
|
|
56
|
+
*
|
|
57
|
+
* @experimental
|
|
58
|
+
* @param request The request.
|
|
59
|
+
*/
|
|
49
60
|
export function bearerToken(request) {
|
|
50
61
|
const header = request.headers.get('authorization');
|
|
51
62
|
const match = header ? /^Bearer +([A-Za-z0-9._~+/-]+=*) *$/i.exec(header) : null;
|
|
@@ -64,6 +75,11 @@ function withDirective(csp, directive, sources) {
|
|
|
64
75
|
* actions that need a permission. Needs sessions() and auth().
|
|
65
76
|
*
|
|
66
77
|
* @experimental Still being designed: may change, or go, without a deprecation period.
|
|
78
|
+
* @param options How users are loaded, which clients may sign in, and where grants are kept.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* oauthServer({ loadUser: (id) => findUser(db, id), clients: ['https://claude.ai/oauth/mcp-client'], store: oauthStore(db) })
|
|
82
|
+
* ```
|
|
67
83
|
*/
|
|
68
84
|
export function oauthServer(options) {
|
|
69
85
|
if (typeof options.loadUser !== 'function')
|