@auth-craft/pages-auth-proxy 1.2.0 → 1.4.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/README.md +160 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth-client.d.ts +53 -0
- package/dist/oauth-client.d.ts.map +1 -0
- package/dist/oauth-client.js +293 -0
- package/dist/oauth-client.js.map +1 -0
- package/dist/pages.d.ts +9 -3
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +12 -0
- package/dist/pages.js.map +1 -1
- package/dist/proxy.d.ts +50 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +90 -20
- package/dist/proxy.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,15 +78,174 @@ const proxy = createAuthProxy({
|
|
|
78
78
|
export default { fetch: (req: Request) => proxy(req) };
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
## In front of the D1 Worker (no gateway)
|
|
82
|
+
|
|
83
|
+
The D1 auth Worker (`apps/auth-worker-d1`) serves `/{app}/...` itself, so point
|
|
84
|
+
`gateway` (Service Binding) or `gatewayUrl` straight at it; `edgeGateSecret` is not
|
|
85
|
+
needed. With `scope` locked, the Worker receives `/{scope}/auth/...` and treats every
|
|
86
|
+
request as that app. A client that also sends an `X-Auth-Context` naming another app is
|
|
87
|
+
refused with 400 `APP_CONFLICT` (the gateway used to overwrite the header instead). An
|
|
88
|
+
access token of another app is refused with 403 `TOKEN_APP_MISMATCH`.
|
|
89
|
+
|
|
90
|
+
## Storefront origin in emails (`originStampSecret`)
|
|
91
|
+
|
|
92
|
+
A platform serving many storefronts on their own domains under one `customer` app can
|
|
93
|
+
tell, in each email, which store the request came from. Set the same secret on the
|
|
94
|
+
proxy (`originStampSecret`, Pages env `ORIGIN_STAMP_SECRET`) and on the backend
|
|
95
|
+
(`ORIGIN_STAMP_SECRET`; on aws-cf-stack `LAMBDA_ORIGIN_STAMP_SECRET`). The proxy then
|
|
96
|
+
sends `X-Auth-Origin` — the origin of the URL Cloudflare routed to it, which the client
|
|
97
|
+
cannot choose — and `X-Origin-Stamp: <secret>`. The backend puts that origin in every
|
|
98
|
+
email it sends for the request as `variables.origin`. Whatever `X-Auth-Origin` /
|
|
99
|
+
`X-Origin-Stamp` the client sent is removed first, and the backend ignores the origin
|
|
100
|
+
when the stamp does not match. Check the value against your own domain list before
|
|
101
|
+
using it (name, logo, sender, links).
|
|
102
|
+
|
|
103
|
+
## A site customers do not sign in on (`allowedPaths`)
|
|
104
|
+
|
|
105
|
+
Lock the proxy to the paths the site needs; every other path gets a bare 404, so no
|
|
106
|
+
login form can post through that origin:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
createAuthProxy({
|
|
110
|
+
scope: 'customer',
|
|
111
|
+
gateway: env.AUTH_GATEWAY,
|
|
112
|
+
originStampSecret: env.ORIGIN_STAMP_SECRET,
|
|
113
|
+
allowedPaths: ['/auth/refresh', '/auth/logout', '/auth/me'],
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Customers sign in on another origin (`oauthClient`)
|
|
118
|
+
|
|
119
|
+
A path is not a boundary: a script on any page of `shop.example` can draw a fake login
|
|
120
|
+
form at `shop.example/login` and call `/auth/refresh`. When your platform lets others run
|
|
121
|
+
scripts on a site, sign customers in on an origin you control (`account.shop.example`)
|
|
122
|
+
and make the site an OAuth 2.0 client (authorization code + PKCE). This proxy does the
|
|
123
|
+
client's part ([RFC 10017 §6.2](https://www.rfc-editor.org/rfc/rfc10017.html)):
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// shop.example
|
|
127
|
+
createAuthProxy({
|
|
128
|
+
scope: 'customer',
|
|
129
|
+
gateway: env.AUTH_GATEWAY,
|
|
130
|
+
originStampSecret: env.ORIGIN_STAMP_SECRET,
|
|
131
|
+
allowedPaths: ['/auth/refresh', '/auth/logout', '/auth/me'],
|
|
132
|
+
// Or a function of the request, when one deployment serves many stores.
|
|
133
|
+
oauthClient: {
|
|
134
|
+
clientId: 'shop',
|
|
135
|
+
authorizeUrl: 'https://account.shop.example/login',
|
|
136
|
+
issuer: 'https://account.shop.example',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- Link to `/auth/login?returnTo=/cart`. The proxy sends the visitor to `authorizeUrl`.
|
|
142
|
+
- The sign-in page signs the customer in as usual, then calls
|
|
143
|
+
`client.auth.oauth2Authorize({ body })` with the query it was opened with and navigates
|
|
144
|
+
to `redirectTo`. `403 OAUTH_LOGIN_REQUIRED` means: sign in first. Serve that page with
|
|
145
|
+
`frame-ancestors 'none'` and no third-party script; its own proxy has no `oauthClient`.
|
|
146
|
+
- `/auth/callback` (register `https://shop.example/auth/callback` as the redirect URI)
|
|
147
|
+
exchanges the code, sets the HttpOnly refresh cookie and returns to the page. On
|
|
148
|
+
failure the page gets `?auth_error=<code>`.
|
|
149
|
+
|
|
150
|
+
The shop's session is an ordinary one (it refreshes at `/auth/refresh`, a sign-out ends
|
|
151
|
+
it), limited to what its scope opens: `profile` is `/auth/me`. Account settings are
|
|
152
|
+
refused there; customers change them on the account origin, signing in again.
|
|
153
|
+
|
|
154
|
+
Needs the app's token strategy `cookie`, `ORIGIN_STAMP_SECRET` on the backend, and an
|
|
155
|
+
`authClients` plugin there (`AUTH_CLIENTS_URL` on the prebuilt servers).
|
|
156
|
+
|
|
157
|
+
## Silent sign-in (`oauthClient.silent`)
|
|
158
|
+
|
|
159
|
+
With the account origin's session kept (`session.keep`), the shop can recognise a
|
|
160
|
+
customer who signed in there as soon as a page loads, without a click or a page change:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
// shop.example
|
|
164
|
+
createAuthProxy({
|
|
165
|
+
scope: 'customer',
|
|
166
|
+
gateway: env.AUTH_GATEWAY,
|
|
167
|
+
originStampSecret: env.ORIGIN_STAMP_SECRET,
|
|
168
|
+
allowedPaths: ['/auth/refresh', '/auth/logout', '/auth/me'],
|
|
169
|
+
oauthClient: { clientId: 'shop', authorizeUrl: 'https://account.shop.example/login', issuer: 'https://account.shop.example', silent: true },
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// account.shop.example: the one path a shop page may call there
|
|
173
|
+
createAuthProxy({
|
|
174
|
+
scope: 'customer',
|
|
175
|
+
gateway: env.AUTH_GATEWAY,
|
|
176
|
+
originStampSecret: env.ORIGIN_STAMP_SECRET,
|
|
177
|
+
crossOriginPaths: ['/auth/oauth2/silent-authorize'],
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The page calls `silentSignIn()` of `@auth-craft/client` (or does the three steps itself):
|
|
182
|
+
|
|
183
|
+
1. `POST /auth/silent/start` (same origin) → `{ url, body }`, or `204`: the customer
|
|
184
|
+
signed out here, do not ask.
|
|
185
|
+
2. `fetch(url, { method: 'POST', credentials: 'include', headers: { 'Content-Type':
|
|
186
|
+
'application/x-www-form-urlencoded' }, body })` → `{ code, state, iss }`, or
|
|
187
|
+
`{ error: 'login_required', state }` (a guest).
|
|
188
|
+
3. `POST /auth/silent/finish` (same origin) with that JSON → `204`: the session cookie is
|
|
189
|
+
set; refresh as usual. `400`: a guest.
|
|
190
|
+
|
|
191
|
+
The PKCE verifier and state stay in an HttpOnly cookie of this proxy (`auth_silent_*`,
|
|
192
|
+
60 seconds, its own name so it never replaces a sign-in clicked in another tab). A sign-out
|
|
193
|
+
through this proxy sets `auth_silent_off` (30 days): silent sign-in stays off until the
|
|
194
|
+
customer signs in by clicking, so signing out of the shop holds even while the account page
|
|
195
|
+
is signed in. Sign the customer out of the account page as well when you mean "everywhere".
|
|
196
|
+
|
|
197
|
+
Needs: `{H}` and `account.{H}` on one site (the account page's `SameSite=Strict` cookie
|
|
198
|
+
goes along with a same-site `fetch`; a store on a public-suffix subdomain gets
|
|
199
|
+
`login_required`), `session: { keep: true, silent: true }` in the auth-client answer, and a
|
|
200
|
+
browser that sends `Sec-Fetch-Site` (others stay guests until they click).
|
|
201
|
+
|
|
81
202
|
## Security notes
|
|
82
203
|
|
|
83
204
|
- **Not a CORS replacement — better.** Same-origin requests have no CORS at all. Site
|
|
84
205
|
isolation comes from first-party `SameSite` cookies + `HttpOnly` + the backend's CSRF
|
|
85
206
|
Origin check (`trustedOrigins`), not from CORS.
|
|
207
|
+
- **This origin only.** A request whose `Origin` is not the proxy's own gets a bare 403
|
|
208
|
+
and never reaches the gateway, and no answer carries the gateway's `Access-Control-*`
|
|
209
|
+
headers. `SameSite=Strict` does not separate `shop.example` from
|
|
210
|
+
`account.shop.example` (one site): without this, a script on the shop could refresh
|
|
211
|
+
the account page's session through its proxy and read the token whenever the gateway's
|
|
212
|
+
CORS allowlist and the backend's `trustedOrigins` name the shop. `crossOriginPaths`
|
|
213
|
+
lists the exceptions, exact paths as the client calls them (an account page that
|
|
214
|
+
serves silent sign-in: `['/auth/oauth2/silent-authorize']`). Requests without `Origin`
|
|
215
|
+
(navigations, same-origin GETs) are forwarded as before.
|
|
86
216
|
- **Scope is enforced, not trusted.** With `scope` set, the prepended segment is the
|
|
87
217
|
lock's value; the client's path is normalized (`..` collapsed) before matching, so it
|
|
88
218
|
can't smuggle another scope. A customer app physically cannot reach system/tenant —
|
|
89
219
|
even against one shared gateway worker. Use one locked proxy per app/scope.
|
|
90
220
|
- Keep `EDGE_GATE_SECRET` in a Pages **secret**. With a Service Binding you can configure
|
|
91
221
|
the gateway to trust the binding and avoid exposing the gate entirely.
|
|
92
|
-
- The proxy preserves method, body, headers and cookies
|
|
222
|
+
- The proxy preserves method, body, headers and cookies. It adds `X-Edge-Gate` and, with
|
|
223
|
+
`originStampSecret`, `X-Auth-Origin` and `X-Origin-Stamp`; those two are always removed
|
|
224
|
+
from what the client sent.
|
|
225
|
+
|
|
226
|
+
## Changelog
|
|
227
|
+
|
|
228
|
+
### 1.4.0
|
|
229
|
+
|
|
230
|
+
Silent sign-in needs `@auth-craft/aws-cf-stack` 2.7.0, `@auth-craft/worker-d1-stack` 0.7.0
|
|
231
|
+
or server-postgres 3.6.0; the origin check works with any server.
|
|
232
|
+
|
|
233
|
+
**Check before upgrading:** a request from another origin (`Origin` not the proxy's own)
|
|
234
|
+
is refused with 403 and is not forwarded; answers no longer carry the gateway's CORS
|
|
235
|
+
headers. The proxy was always meant for its own origin; a deployment that calls it from
|
|
236
|
+
another origin lists those paths in `crossOriginPaths`.
|
|
237
|
+
|
|
238
|
+
- The proxy answers its own origin only (see Security notes). Closes: a script on a
|
|
239
|
+
sibling origin of the same site (the shop next to its account page) could refresh the
|
|
240
|
+
account page's session and read its access token.
|
|
241
|
+
- `crossOriginPaths`: paths that answer other origins, with the gateway's CORS headers.
|
|
242
|
+
- `oauthClient.silent`, `silentAuthorizeUrl`, `silentStartPath`, `silentFinishPath`: silent sign-in (needs the server's `/auth/oauth2/silent-authorize`). A sign-out through a proxy with `oauthClient` sets `auth_silent_off`; a clicked sign-in clears it.
|
|
243
|
+
|
|
244
|
+
### 1.3.0
|
|
245
|
+
|
|
246
|
+
Additive. The new options need `@auth-craft/aws-cf-stack` 2.3.0 (backend and gateway),
|
|
247
|
+
`@auth-craft/worker-d1-stack` 0.3.0 or server-postgres 3.2.0.
|
|
248
|
+
|
|
249
|
+
- `originStampSecret` (Pages `ORIGIN_STAMP_SECRET`): stamps the origin the proxy was reached on. A client-sent `X-Auth-Origin` / `X-Origin-Stamp` is now always removed, with or without it.
|
|
250
|
+
- `allowedPaths`: only these paths are forwarded.
|
|
251
|
+
- `oauthClient`, `loginPath`, `callbackPath`: the site is an OAuth 2.0 client (authorization code + PKCE) of a sign-in page on another origin. Without `oauthClient`, `/auth/login` and `/auth/callback` are forwarded as before.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Framework-agnostic core: `createAuthProxy`. For Cloudflare Pages Functions use the
|
|
9
9
|
* `@auth-craft/pages-auth-proxy/pages` subpath.
|
|
10
10
|
*/
|
|
11
|
+
export type { OAuthClientOptions, OAuthClientResolver } from './oauth-client.js';
|
|
11
12
|
export type { AuthProxyOptions, AuthScope, ProxyFetcher } from './proxy.js';
|
|
12
13
|
export { createAuthProxy } from './proxy.js';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACjF,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The proxy as an OAuth 2.0 client (RFC 10017 §6.2 token-mediating backend): a site whose
|
|
3
|
+
* customers sign in on another origin gets its session here, not in the page.
|
|
4
|
+
*
|
|
5
|
+
* `GET {loginPath}?returnTo=/x` → the sign-in page, with a PKCE authorization request.
|
|
6
|
+
* `GET {callbackPath}` → exchanges the code, sets the refresh cookie, → returnTo.
|
|
7
|
+
*
|
|
8
|
+
* With `silent` (docs/SNAPSHOT_COMMERCE_PLAN_K.md K4), the same without a page change:
|
|
9
|
+
* `POST {silentStartPath}` → `{ url, body }`: what the page sends to the account origin.
|
|
10
|
+
* `POST {silentFinishPath}` → `{ state, code, iss }` from that answer: exchanges, sets the
|
|
11
|
+
* refresh cookie, 204.
|
|
12
|
+
* After a sign-out through this proxy, start answers 204 (do not ask) until the customer
|
|
13
|
+
* signs in by clicking again.
|
|
14
|
+
*
|
|
15
|
+
* The verifier and state live in an HttpOnly, encrypted, per-flow cookie: a script on the
|
|
16
|
+
* site can neither read nor replace them, so a code it gets hold of is useless.
|
|
17
|
+
*/
|
|
18
|
+
export interface OAuthClientOptions {
|
|
19
|
+
clientId: string;
|
|
20
|
+
/** The sign-in page that takes the authorization request, e.g. `https://account.shop.example/login`. */
|
|
21
|
+
authorizeUrl: string;
|
|
22
|
+
/** Expected `iss` of the response (RFC 9207): the sign-in page's origin. */
|
|
23
|
+
issuer: string;
|
|
24
|
+
/** @default 'profile' */
|
|
25
|
+
scope?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Silent sign-in: pages of this site may get the session kept on the account origin
|
|
28
|
+
* without a click. Needs `session: { keep: true, silent: true }` in the auth-client
|
|
29
|
+
* answer for this client, and the account origin's proxy listing
|
|
30
|
+
* `/auth/oauth2/silent-authorize` in `crossOriginPaths`.
|
|
31
|
+
*/
|
|
32
|
+
silent?: boolean;
|
|
33
|
+
/** @default `${issuer}/auth/oauth2/silent-authorize` */
|
|
34
|
+
silentAuthorizeUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
/** One client, or the client of the host a request came to (`null`: none there). */
|
|
37
|
+
export type OAuthClientResolver = OAuthClientOptions | ((request: Request) => OAuthClientOptions | null | Promise<OAuthClientOptions | null>);
|
|
38
|
+
export interface OAuthClientDeps {
|
|
39
|
+
resolve: OAuthClientResolver;
|
|
40
|
+
loginPath: string;
|
|
41
|
+
callbackPath: string;
|
|
42
|
+
silentStartPath: string;
|
|
43
|
+
silentFinishPath: string;
|
|
44
|
+
/** Key material for the flow cookie. */
|
|
45
|
+
secret: string;
|
|
46
|
+
/** POST the token request through the gateway, stamped with the request's origin. */
|
|
47
|
+
exchange: (request: Request, form: URLSearchParams) => Promise<Response>;
|
|
48
|
+
}
|
|
49
|
+
/** The cookie a sign-out through the proxy sets (see `handleOAuthClient`). */
|
|
50
|
+
export declare function silentOffCookie(url: URL): string;
|
|
51
|
+
/** Answers the two paths; `null` for any other request. */
|
|
52
|
+
export declare function handleOAuthClient(request: Request, deps: OAuthClientDeps): Promise<Response | null>;
|
|
53
|
+
//# sourceMappingURL=oauth-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-client.d.ts","sourceRoot":"","sources":["../src/oauth-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,wGAAwG;IACxG,YAAY,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAC3B,kBAAkB,GAClB,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,kBAAkB,GAAG,IAAI,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC,CAAC;AAE3F,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,mBAAmB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC1E;AAgHD,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAEhD;AAeD,2DAA2D;AAC3D,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAkBzG"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The proxy as an OAuth 2.0 client (RFC 10017 §6.2 token-mediating backend): a site whose
|
|
3
|
+
* customers sign in on another origin gets its session here, not in the page.
|
|
4
|
+
*
|
|
5
|
+
* `GET {loginPath}?returnTo=/x` → the sign-in page, with a PKCE authorization request.
|
|
6
|
+
* `GET {callbackPath}` → exchanges the code, sets the refresh cookie, → returnTo.
|
|
7
|
+
*
|
|
8
|
+
* With `silent` (docs/SNAPSHOT_COMMERCE_PLAN_K.md K4), the same without a page change:
|
|
9
|
+
* `POST {silentStartPath}` → `{ url, body }`: what the page sends to the account origin.
|
|
10
|
+
* `POST {silentFinishPath}` → `{ state, code, iss }` from that answer: exchanges, sets the
|
|
11
|
+
* refresh cookie, 204.
|
|
12
|
+
* After a sign-out through this proxy, start answers 204 (do not ask) until the customer
|
|
13
|
+
* signs in by clicking again.
|
|
14
|
+
*
|
|
15
|
+
* The verifier and state live in an HttpOnly, encrypted, per-flow cookie: a script on the
|
|
16
|
+
* site can neither read nor replace them, so a code it gets hold of is useless.
|
|
17
|
+
*/
|
|
18
|
+
const FLOW_SECONDS = 600;
|
|
19
|
+
const SILENT_FLOW_SECONDS = 60;
|
|
20
|
+
const COOKIE = 'auth_flow_';
|
|
21
|
+
/** Its own name: a silent flow never replaces a sign-in the customer clicked in another tab. */
|
|
22
|
+
const SILENT_COOKIE = 'auth_silent_';
|
|
23
|
+
/** Set by a sign-out through this proxy: no silent sign-in until a clicked one. */
|
|
24
|
+
const SILENT_OFF = 'auth_silent_off';
|
|
25
|
+
const SILENT_OFF_SECONDS = 30 * 24 * 60 * 60;
|
|
26
|
+
function base64url(bytes) {
|
|
27
|
+
let bin = '';
|
|
28
|
+
for (const b of bytes)
|
|
29
|
+
bin += String.fromCharCode(b);
|
|
30
|
+
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
31
|
+
}
|
|
32
|
+
function fromBase64url(text) {
|
|
33
|
+
const bin = atob(text.replace(/-/g, '+').replace(/_/g, '/'));
|
|
34
|
+
return Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
35
|
+
}
|
|
36
|
+
const random = () => base64url(crypto.getRandomValues(new Uint8Array(32)));
|
|
37
|
+
const utf8 = (text) => new TextEncoder().encode(text);
|
|
38
|
+
async function flowKey(secret) {
|
|
39
|
+
const material = await crypto.subtle.importKey('raw', utf8(secret), 'HKDF', false, ['deriveKey']);
|
|
40
|
+
return crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: utf8('pages-auth-proxy/oauth-flow') }, material, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
41
|
+
}
|
|
42
|
+
/** Bound to the site and client: one store's flow cookie means nothing at another's. */
|
|
43
|
+
const aad = (origin, clientId) => utf8(`${origin}\n${clientId}`);
|
|
44
|
+
async function seal(flow, secret, origin, clientId) {
|
|
45
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
46
|
+
const sealed = await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData: aad(origin, clientId) }, await flowKey(secret), utf8(JSON.stringify(flow)));
|
|
47
|
+
return `${base64url(iv)}.${base64url(new Uint8Array(sealed))}`;
|
|
48
|
+
}
|
|
49
|
+
async function unseal(value, secret, origin, clientId) {
|
|
50
|
+
try {
|
|
51
|
+
const [iv, data] = value.split('.');
|
|
52
|
+
if (!iv || !data)
|
|
53
|
+
return null;
|
|
54
|
+
const plain = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: fromBase64url(iv), additionalData: aad(origin, clientId) }, await flowKey(secret), fromBase64url(data));
|
|
55
|
+
return JSON.parse(new TextDecoder().decode(plain));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A path on this origin, or '/': anything else would make sign-in an open redirect. */
|
|
62
|
+
function safeReturnTo(value, origin, own) {
|
|
63
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is being refused
|
|
64
|
+
if (!value?.startsWith('/') || value.startsWith('//') || /[\\\u0000-\u001f]/.test(value))
|
|
65
|
+
return '/';
|
|
66
|
+
try {
|
|
67
|
+
const url = new URL(value, origin);
|
|
68
|
+
if (url.origin !== origin || own.includes(url.pathname))
|
|
69
|
+
return '/';
|
|
70
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return '/';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** `__Host-` (Secure, host-only) except on plain-http localhost, where a browser refuses it. */
|
|
77
|
+
function cookieName(url, base) {
|
|
78
|
+
return `${url.protocol === 'https:' ? '__Host-' : ''}${base}`;
|
|
79
|
+
}
|
|
80
|
+
function cookie(url, state, value, maxAge, base = COOKIE) {
|
|
81
|
+
return namedCookie(url, `${base}${state.slice(0, 16)}`, value, maxAge);
|
|
82
|
+
}
|
|
83
|
+
function namedCookie(url, base, value, maxAge) {
|
|
84
|
+
const secure = url.protocol === 'https:';
|
|
85
|
+
return `${cookieName(url, base)}=${value}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${maxAge}${secure ? '; Secure' : ''}`;
|
|
86
|
+
}
|
|
87
|
+
function readNamedCookie(request, name) {
|
|
88
|
+
for (const part of (request.headers.get('cookie') ?? '').split(';')) {
|
|
89
|
+
const eq = part.indexOf('=');
|
|
90
|
+
if (eq > 0 && part.slice(0, eq).trim() === name)
|
|
91
|
+
return part.slice(eq + 1).trim();
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
function readCookie(request, url, state, base = COOKIE) {
|
|
96
|
+
return readNamedCookie(request, cookieName(url, `${base}${state.slice(0, 16)}`));
|
|
97
|
+
}
|
|
98
|
+
/** The cookie a sign-out through the proxy sets (see `handleOAuthClient`). */
|
|
99
|
+
export function silentOffCookie(url) {
|
|
100
|
+
return namedCookie(url, SILENT_OFF, '1', SILENT_OFF_SECONDS);
|
|
101
|
+
}
|
|
102
|
+
function redirect(location, setCookies = []) {
|
|
103
|
+
const headers = new Headers({ Location: location, 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' });
|
|
104
|
+
for (const c of setCookies)
|
|
105
|
+
headers.append('Set-Cookie', c);
|
|
106
|
+
return new Response(null, { status: 303, headers });
|
|
107
|
+
}
|
|
108
|
+
/** Back to the site with the reason in `auth_error` (an OAuth error code). */
|
|
109
|
+
function failed(returnTo, origin, error, setCookies = []) {
|
|
110
|
+
const url = new URL(returnTo, origin);
|
|
111
|
+
url.searchParams.set('auth_error', /^[a-z_]{1,40}$/.test(error) ? error : 'server_error');
|
|
112
|
+
return redirect(`${url.pathname}${url.search}${url.hash}`, setCookies);
|
|
113
|
+
}
|
|
114
|
+
/** Answers the two paths; `null` for any other request. */
|
|
115
|
+
export async function handleOAuthClient(request, deps) {
|
|
116
|
+
const url = new URL(request.url);
|
|
117
|
+
const path = url.pathname;
|
|
118
|
+
if (path === deps.silentStartPath || path === deps.silentFinishPath) {
|
|
119
|
+
if (request.method !== 'POST')
|
|
120
|
+
return new Response(null, { status: 405, headers: { Allow: 'POST' } });
|
|
121
|
+
// A page of this site only; the K0 rule of the proxy, here before anything is read.
|
|
122
|
+
if (request.headers.get('Origin') !== url.origin)
|
|
123
|
+
return new Response(null, { status: 403 });
|
|
124
|
+
const client = typeof deps.resolve === 'function' ? await deps.resolve(request) : deps.resolve;
|
|
125
|
+
if (!client?.silent)
|
|
126
|
+
return new Response(null, { status: 404 });
|
|
127
|
+
return path === deps.silentStartPath
|
|
128
|
+
? silentStart(request, url, client, deps)
|
|
129
|
+
: silentFinish(request, url, client, deps);
|
|
130
|
+
}
|
|
131
|
+
if (path !== deps.loginPath && path !== deps.callbackPath)
|
|
132
|
+
return null;
|
|
133
|
+
if (request.method !== 'GET')
|
|
134
|
+
return new Response(null, { status: 405, headers: { Allow: 'GET' } });
|
|
135
|
+
const client = typeof deps.resolve === 'function' ? await deps.resolve(request) : deps.resolve;
|
|
136
|
+
if (!client)
|
|
137
|
+
return new Response(null, { status: 404 });
|
|
138
|
+
return path === deps.loginPath ? start(url, client, deps) : finish(request, url, client, deps);
|
|
139
|
+
}
|
|
140
|
+
const json = (body, status, setCookies = []) => {
|
|
141
|
+
const headers = new Headers({ 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
142
|
+
for (const c of setCookies)
|
|
143
|
+
headers.append('Set-Cookie', c);
|
|
144
|
+
return new Response(JSON.stringify(body), { status, headers });
|
|
145
|
+
};
|
|
146
|
+
/** The request the page sends to the account origin, with this flow's PKCE. */
|
|
147
|
+
async function silentStart(request, url, client, deps) {
|
|
148
|
+
// Signed out here: do not sign back in behind the customer's back.
|
|
149
|
+
if (readNamedCookie(request, cookieName(url, SILENT_OFF)) !== null) {
|
|
150
|
+
return new Response(null, { status: 204, headers: { 'Cache-Control': 'no-store' } });
|
|
151
|
+
}
|
|
152
|
+
const flow = {
|
|
153
|
+
state: random(),
|
|
154
|
+
verifier: random(),
|
|
155
|
+
returnTo: '/',
|
|
156
|
+
expiresAt: Date.now() + SILENT_FLOW_SECONDS * 1000,
|
|
157
|
+
silent: true,
|
|
158
|
+
};
|
|
159
|
+
const challenge = base64url(new Uint8Array(await crypto.subtle.digest('SHA-256', utf8(flow.verifier))));
|
|
160
|
+
const body = new URLSearchParams({
|
|
161
|
+
response_type: 'code',
|
|
162
|
+
client_id: client.clientId,
|
|
163
|
+
redirect_uri: `${url.origin}${deps.callbackPath}`,
|
|
164
|
+
scope: client.scope ?? 'profile',
|
|
165
|
+
state: flow.state,
|
|
166
|
+
code_challenge: challenge,
|
|
167
|
+
code_challenge_method: 'S256',
|
|
168
|
+
});
|
|
169
|
+
const sealed = await seal(flow, deps.secret, url.origin, client.clientId);
|
|
170
|
+
return json({ url: client.silentAuthorizeUrl ?? `${client.issuer}/auth/oauth2/silent-authorize`, body: body.toString() }, 200, [cookie(url, flow.state, sealed, SILENT_FLOW_SECONDS, SILENT_COOKIE)]);
|
|
171
|
+
}
|
|
172
|
+
/** The account origin's answer, as the page got it: exchange the code, set the session. */
|
|
173
|
+
async function silentFinish(request, url, client, deps) {
|
|
174
|
+
let input;
|
|
175
|
+
try {
|
|
176
|
+
const text = await request.text();
|
|
177
|
+
input = text.length > 4096 ? {} : JSON.parse(text);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
input = {};
|
|
181
|
+
}
|
|
182
|
+
const field = (name) => (typeof input[name] === 'string' ? input[name] : undefined);
|
|
183
|
+
const state = field('state');
|
|
184
|
+
if (!state || !/^[A-Za-z0-9_-]{43}$/.test(state))
|
|
185
|
+
return json({ error: 'invalid_request' }, 400);
|
|
186
|
+
const sealed = readCookie(request, url, state, SILENT_COOKIE);
|
|
187
|
+
const flow = sealed ? await unseal(sealed, deps.secret, url.origin, client.clientId) : null;
|
|
188
|
+
const clear = [cookie(url, state, '', 0, SILENT_COOKIE)];
|
|
189
|
+
if (!flow || !flow.silent || flow.state !== state || flow.expiresAt <= Date.now()) {
|
|
190
|
+
return json({ error: 'invalid_request' }, 400, clear);
|
|
191
|
+
}
|
|
192
|
+
const error = field('error');
|
|
193
|
+
if (error)
|
|
194
|
+
return json({ error: /^[a-z_]{1,40}$/.test(error) ? error : 'invalid_request' }, 400, clear);
|
|
195
|
+
// The answer of another authorization server (RFC 9207): its code must not be sent to ours.
|
|
196
|
+
const code = field('code');
|
|
197
|
+
if (field('iss') !== client.issuer || !code)
|
|
198
|
+
return json({ error: 'invalid_request' }, 400, clear);
|
|
199
|
+
const exchanged = await exchangeCode(request, url, client, deps, code, flow.verifier);
|
|
200
|
+
if ('error' in exchanged)
|
|
201
|
+
return json({ error: exchanged.error }, exchanged.status, clear);
|
|
202
|
+
return new Response(null, {
|
|
203
|
+
status: 204,
|
|
204
|
+
headers: [
|
|
205
|
+
['Cache-Control', 'no-store'],
|
|
206
|
+
...[...clear, ...exchanged.cookies].map((c) => ['Set-Cookie', c]),
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/** The token request; the session's cookies, or why there is none. */
|
|
211
|
+
async function exchangeCode(request, url, client, deps, code, verifier) {
|
|
212
|
+
const form = new URLSearchParams({
|
|
213
|
+
grant_type: 'authorization_code',
|
|
214
|
+
code,
|
|
215
|
+
client_id: client.clientId,
|
|
216
|
+
redirect_uri: `${url.origin}${deps.callbackPath}`,
|
|
217
|
+
code_verifier: verifier,
|
|
218
|
+
});
|
|
219
|
+
let answer;
|
|
220
|
+
let body;
|
|
221
|
+
try {
|
|
222
|
+
answer = await deps.exchange(request, form);
|
|
223
|
+
body = (await answer.json());
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return { error: 'temporarily_unavailable', status: 502 };
|
|
227
|
+
}
|
|
228
|
+
if (!answer.ok) {
|
|
229
|
+
return { error: typeof body.error === 'string' ? body.error : 'server_error', status: 400 };
|
|
230
|
+
}
|
|
231
|
+
const cookies = answer.headers.getSetCookie();
|
|
232
|
+
if (body.refresh_token !== undefined || cookies.length === 0) {
|
|
233
|
+
// Forwarding a refresh token would hand it to the page; dropping it would lose the session.
|
|
234
|
+
console.error("[pages-auth-proxy] oauthClient needs the app's token strategy to be 'cookie'");
|
|
235
|
+
return { error: 'server_error', status: 502 };
|
|
236
|
+
}
|
|
237
|
+
return { cookies };
|
|
238
|
+
}
|
|
239
|
+
async function start(url, client, deps) {
|
|
240
|
+
const flow = {
|
|
241
|
+
state: random(),
|
|
242
|
+
verifier: random(),
|
|
243
|
+
returnTo: safeReturnTo(url.searchParams.get('returnTo'), url.origin, [deps.loginPath, deps.callbackPath]),
|
|
244
|
+
expiresAt: Date.now() + FLOW_SECONDS * 1000,
|
|
245
|
+
};
|
|
246
|
+
const challenge = base64url(new Uint8Array(await crypto.subtle.digest('SHA-256', utf8(flow.verifier))));
|
|
247
|
+
const target = new URL(client.authorizeUrl);
|
|
248
|
+
for (const [key, value] of Object.entries({
|
|
249
|
+
response_type: 'code',
|
|
250
|
+
client_id: client.clientId,
|
|
251
|
+
redirect_uri: `${url.origin}${deps.callbackPath}`,
|
|
252
|
+
scope: client.scope ?? 'profile',
|
|
253
|
+
state: flow.state,
|
|
254
|
+
code_challenge: challenge,
|
|
255
|
+
code_challenge_method: 'S256',
|
|
256
|
+
})) {
|
|
257
|
+
target.searchParams.set(key, value);
|
|
258
|
+
}
|
|
259
|
+
const sealed = await seal(flow, deps.secret, url.origin, client.clientId);
|
|
260
|
+
return redirect(target.toString(), [cookie(url, flow.state, sealed, FLOW_SECONDS)]);
|
|
261
|
+
}
|
|
262
|
+
async function finish(request, url, client, deps) {
|
|
263
|
+
const param = (name) => {
|
|
264
|
+
const all = url.searchParams.getAll(name);
|
|
265
|
+
return all.length === 1 ? (all[0] ?? null) : null;
|
|
266
|
+
};
|
|
267
|
+
const state = param('state');
|
|
268
|
+
if (!state || !/^[A-Za-z0-9_-]{43}$/.test(state))
|
|
269
|
+
return failed('/', url.origin, 'invalid_request');
|
|
270
|
+
const sealed = readCookie(request, url, state);
|
|
271
|
+
const flow = sealed ? await unseal(sealed, deps.secret, url.origin, client.clientId) : null;
|
|
272
|
+
const clear = [cookie(url, state, '', 0)];
|
|
273
|
+
// Not a flow this browser started here (or an old one): nothing to exchange.
|
|
274
|
+
if (!flow || flow.silent || flow.state !== state || flow.expiresAt <= Date.now()) {
|
|
275
|
+
return failed('/', url.origin, 'invalid_request', clear);
|
|
276
|
+
}
|
|
277
|
+
// The answer of another authorization server (RFC 9207): its code must not be sent to ours.
|
|
278
|
+
if (param('iss') !== client.issuer)
|
|
279
|
+
return failed(flow.returnTo, url.origin, 'invalid_request', clear);
|
|
280
|
+
const error = param('error');
|
|
281
|
+
if (error)
|
|
282
|
+
return failed(flow.returnTo, url.origin, error, clear);
|
|
283
|
+
const code = param('code');
|
|
284
|
+
if (!code)
|
|
285
|
+
return failed(flow.returnTo, url.origin, 'invalid_request', clear);
|
|
286
|
+
const exchanged = await exchangeCode(request, url, client, deps, code, flow.verifier);
|
|
287
|
+
if ('error' in exchanged)
|
|
288
|
+
return failed(flow.returnTo, url.origin, exchanged.error, clear);
|
|
289
|
+
// A clicked sign-in lifts the sign-out's hold on silent sign-in.
|
|
290
|
+
const lift = client.silent ? [namedCookie(url, SILENT_OFF, '', 0)] : [];
|
|
291
|
+
return redirect(flow.returnTo, [...clear, ...lift, ...exchanged.cookies]);
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=oauth-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-client.js","sourceRoot":"","sources":["../src/oauth-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA+CH,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,MAAM,GAAG,YAAY,CAAC;AAC5B,gGAAgG;AAChG,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,mFAAmF;AACnF,MAAM,UAAU,GAAG,iBAAiB,CAAC;AACrC,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAE7C,SAAS,SAAS,CAAC,KAAiB;IAClC,IAAI,GAAG,GAAG,E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CHANGED
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
* - `AUTH_GATEWAY` — Service Binding to the gateway worker (preferred), OR
|
|
18
18
|
* - `AUTH_GATEWAY_URL` — gateway public URL (fallback when no Service Binding)
|
|
19
19
|
* - `EDGE_GATE_SECRET` — client→gateway gate (Pages secret)
|
|
20
|
+
* - `ORIGIN_STAMP_SECRET` — stamps this site's origin for the backend (Pages secret, optional)
|
|
20
21
|
*
|
|
21
22
|
* Anything outside `prefix` falls through to the rest of the Pages app via `next()`.
|
|
22
23
|
*/
|
|
23
|
-
import
|
|
24
|
+
import type { OAuthClientOptions } from './oauth-client.js';
|
|
25
|
+
import { type AuthProxyOptions, type AuthScope, type ProxyFetcher } from './proxy.js';
|
|
24
26
|
/** Env bindings this adapter reads from the Pages project. */
|
|
25
27
|
export interface PagesProxyEnv {
|
|
26
28
|
/** Service Binding to the gateway worker (preferred). */
|
|
@@ -29,6 +31,8 @@ export interface PagesProxyEnv {
|
|
|
29
31
|
AUTH_GATEWAY_URL?: string;
|
|
30
32
|
/** Client→gateway gate secret, sent as X-Edge-Gate. */
|
|
31
33
|
EDGE_GATE_SECRET?: string;
|
|
34
|
+
/** Shared with the backend; stamps X-Auth-Origin (see `originStampSecret`). */
|
|
35
|
+
ORIGIN_STAMP_SECRET?: string;
|
|
32
36
|
}
|
|
33
37
|
/** Minimal shape of a Pages Functions event context (avoids a hard dep on @cloudflare/workers-types consumers). */
|
|
34
38
|
interface PagesContext<Env extends PagesProxyEnv> {
|
|
@@ -36,7 +40,7 @@ interface PagesContext<Env extends PagesProxyEnv> {
|
|
|
36
40
|
env: Env;
|
|
37
41
|
next: () => Promise<Response>;
|
|
38
42
|
}
|
|
39
|
-
export interface CreatePagesAuthProxyOptions {
|
|
43
|
+
export interface CreatePagesAuthProxyOptions<Env extends PagesProxyEnv = PagesProxyEnv> extends Pick<AuthProxyOptions, 'allowedPaths' | 'crossOriginPaths' | 'loginPath' | 'callbackPath' | 'silentStartPath' | 'silentFinishPath'> {
|
|
40
44
|
/**
|
|
41
45
|
* Lock this proxy to a single auth scope (recommended). The frontend then calls
|
|
42
46
|
* scope-less paths (e.g. `/auth/...`) and the proxy prepends the scope before
|
|
@@ -50,11 +54,13 @@ export interface CreatePagesAuthProxyOptions {
|
|
|
50
54
|
* '' (proxies everything the Function matches).
|
|
51
55
|
*/
|
|
52
56
|
prefix?: string;
|
|
57
|
+
/** See `AuthProxyOptions.oauthClient`; a function also gets the Pages `env`. */
|
|
58
|
+
oauthClient?: OAuthClientOptions | ((request: Request, env: Env) => OAuthClientOptions | null | Promise<OAuthClientOptions | null>);
|
|
53
59
|
}
|
|
54
60
|
/**
|
|
55
61
|
* Build a Pages Functions `onRequest` handler that proxies auth traffic to the gateway.
|
|
56
62
|
* Requests outside `prefix` are handed back to the Pages pipeline via `next()`.
|
|
57
63
|
*/
|
|
58
|
-
export declare function createPagesAuthProxy<Env extends PagesProxyEnv = PagesProxyEnv>(options?: CreatePagesAuthProxyOptions): (context: PagesContext<Env>) => Promise<Response>;
|
|
64
|
+
export declare function createPagesAuthProxy<Env extends PagesProxyEnv = PagesProxyEnv>(options?: CreatePagesAuthProxyOptions<Env>): (context: PagesContext<Env>) => Promise<Response>;
|
|
59
65
|
export {};
|
|
60
66
|
//# sourceMappingURL=pages.d.ts.map
|
package/dist/pages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAmB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEvG,8DAA8D;AAC9D,MAAM,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` — gateway public URL (fallback when no Service Binding)
|
|
19
19
|
* - `EDGE_GATE_SECRET` — client→gateway gate (Pages secret)
|
|
20
|
+
* - `ORIGIN_STAMP_SECRET` — stamps this site's origin for the backend (Pages secret, optional)
|
|
20
21
|
*
|
|
21
22
|
* Anything outside `prefix` falls through to the rest of the Pages app via `next()`.
|
|
22
23
|
*/
|
|
@@ -31,12 +32,23 @@ export function createPagesAuthProxy(options = {}) {
|
|
|
31
32
|
if (!env.AUTH_GATEWAY && !env.AUTH_GATEWAY_URL) {
|
|
32
33
|
throw new Error('pages-auth-proxy: bind AUTH_GATEWAY (Service Binding) or set AUTH_GATEWAY_URL in the Pages project.');
|
|
33
34
|
}
|
|
35
|
+
const { oauthClient } = options;
|
|
34
36
|
const proxy = createAuthProxy({
|
|
37
|
+
...(options.allowedPaths ? { allowedPaths: options.allowedPaths } : {}),
|
|
38
|
+
...(options.crossOriginPaths ? { crossOriginPaths: options.crossOriginPaths } : {}),
|
|
39
|
+
...(options.loginPath !== undefined ? { loginPath: options.loginPath } : {}),
|
|
40
|
+
...(options.callbackPath !== undefined ? { callbackPath: options.callbackPath } : {}),
|
|
41
|
+
...(options.silentStartPath !== undefined ? { silentStartPath: options.silentStartPath } : {}),
|
|
42
|
+
...(options.silentFinishPath !== undefined ? { silentFinishPath: options.silentFinishPath } : {}),
|
|
43
|
+
...(oauthClient
|
|
44
|
+
? { oauthClient: typeof oauthClient === 'function' ? (r) => oauthClient(r, env) : oauthClient }
|
|
45
|
+
: {}),
|
|
35
46
|
...(options.scope !== undefined ? { scope: options.scope } : {}),
|
|
36
47
|
...(options.prefix !== undefined ? { prefix: options.prefix } : {}),
|
|
37
48
|
...(env.AUTH_GATEWAY ? { gateway: env.AUTH_GATEWAY } : {}),
|
|
38
49
|
...(env.AUTH_GATEWAY_URL ? { gatewayUrl: env.AUTH_GATEWAY_URL } : {}),
|
|
39
50
|
...(env.EDGE_GATE_SECRET ? { edgeGateSecret: env.EDGE_GATE_SECRET } : {}),
|
|
51
|
+
...(env.ORIGIN_STAMP_SECRET ? { originStampSecret: env.ORIGIN_STAMP_SECRET } : {}),
|
|
40
52
|
// Outside the prefix → let the rest of the Pages app handle it.
|
|
41
53
|
passthrough: () => next(),
|
|
42
54
|
});
|
package/dist/pages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAyC,eAAe,EAAqB,MAAM,YAAY,CAAC;AA+CvG;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAO,GAAqC,EAAE;IAE9C,OAAO,KAAK,EAAE,OAA0B,EAAqB,EAAE;QAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEvC,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAChC,MAAM,KAAK,GAAG,eAAe,CAAC;YAC5B,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnF,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,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AAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzE,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAClF,gEAAgE;YAChE,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;SAC1B,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/proxy.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* In-network, lowest latency, and `X-Edge-Gate` need not even be exposed.
|
|
18
18
|
* - HTTP: `gatewayUrl` is the gateway's public URL; the proxy fetches it directly.
|
|
19
19
|
*/
|
|
20
|
+
import { type OAuthClientResolver } from './oauth-client.js';
|
|
20
21
|
/** A minimal fetcher — a Cloudflare Service Binding satisfies this. */
|
|
21
22
|
export interface ProxyFetcher {
|
|
22
23
|
fetch(request: Request): Promise<Response>;
|
|
@@ -69,6 +70,55 @@ export interface AuthProxyOptions {
|
|
|
69
70
|
* Pages secret/env binding — never in client code.
|
|
70
71
|
*/
|
|
71
72
|
edgeGateSecret?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Secret shared with the auth backend (`createAuthRouter({ originStampSecret })`,
|
|
75
|
+
* server env `ORIGIN_STAMP_SECRET`). When set, every forwarded request carries
|
|
76
|
+
* `X-Auth-Origin` — the origin of the URL this proxy was reached on, which the client
|
|
77
|
+
* cannot choose — and `X-Origin-Stamp` proving the proxy set it. The backend then
|
|
78
|
+
* puts that origin in every email it sends for the request (which store it is
|
|
79
|
+
* about). A client-sent `X-Auth-Origin` / `X-Origin-Stamp` is always removed. Keep it
|
|
80
|
+
* in a secret binding — never in client code.
|
|
81
|
+
*/
|
|
82
|
+
originStampSecret?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Forward only these paths (exact, as the client calls them, e.g. '/auth/refresh');
|
|
85
|
+
* anything else under `prefix` gets a bare 404. For a site customers do not
|
|
86
|
+
* sign in on: `['/auth/refresh', '/auth/logout', '/auth/me']` — no login form can post
|
|
87
|
+
* through it.
|
|
88
|
+
*/
|
|
89
|
+
allowedPaths?: readonly string[];
|
|
90
|
+
/**
|
|
91
|
+
* Paths (exact, as the client calls them) that answer a page on ANOTHER origin.
|
|
92
|
+
* Everything else is for this origin only: a request whose `Origin` is not this
|
|
93
|
+
* proxy's own gets a bare 403 and never reaches the gateway, and no answer carries
|
|
94
|
+
* the gateway's `Access-Control-*` headers.
|
|
95
|
+
*
|
|
96
|
+
* Why: a sibling origin of the same site (`shop.example` next to
|
|
97
|
+
* `account.shop.example`) sends this origin's `SameSite=Strict` cookies along with
|
|
98
|
+
* its `fetch`. If the gateway's CORS allowlist and the backend's CSRF allowlist name
|
|
99
|
+
* that sibling, which a deployment that proxies it does, a script there could refresh
|
|
100
|
+
* this origin's session and read the token (docs/SNAPSHOT_COMMERCE_PLAN_K.md K0).
|
|
101
|
+
*
|
|
102
|
+
* An account page that serves silent sign-in to its shops lists
|
|
103
|
+
* `['/auth/oauth2/silent-authorize']`. @default []
|
|
104
|
+
*/
|
|
105
|
+
crossOriginPaths?: readonly string[];
|
|
106
|
+
/**
|
|
107
|
+
* Make this site an OAuth 2.0 client: customers sign in on another origin (one no
|
|
108
|
+
* third-party script runs on) and this proxy receives the session. It serves
|
|
109
|
+
* {@link loginPath} and {@link callbackPath} itself. Needs `scope` and
|
|
110
|
+
* `originStampSecret`, a backend with an `authClients` plugin, and the app's token
|
|
111
|
+
* strategy set to `cookie`. Pass a function when one deployment serves many hosts.
|
|
112
|
+
*/
|
|
113
|
+
oauthClient?: OAuthClientResolver;
|
|
114
|
+
/** Where a page sends a visitor to sign in (`?returnTo=/path`). @default '/auth/login' */
|
|
115
|
+
loginPath?: string;
|
|
116
|
+
/** Path of the redirect URI registered for the client. @default '/auth/callback' */
|
|
117
|
+
callbackPath?: string;
|
|
118
|
+
/** Silent sign-in, step 1 (`oauthClient.silent`). @default '/auth/silent/start' */
|
|
119
|
+
silentStartPath?: string;
|
|
120
|
+
/** Silent sign-in, step 2 (`oauthClient.silent`). @default '/auth/silent/finish' */
|
|
121
|
+
silentFinishPath?: string;
|
|
72
122
|
/**
|
|
73
123
|
* Response returned for requests outside `prefix`. Lets the proxy coexist with the
|
|
74
124
|
* app's own handlers. Defaults to a bare 404.
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAqB,KAAK,mBAAmB,EAAmB,MAAM,mBAAmB,CAAC;AAEjG,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAM/B,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEjC;;;;;;;;;;;;;;OAcG;IACH,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAErC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAElC,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;CAClE;AA+CD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAyFlG"}
|
package/dist/proxy.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* In-network, lowest latency, and `X-Edge-Gate` need not even be exposed.
|
|
18
18
|
* - HTTP: `gatewayUrl` is the gateway's public URL; the proxy fetches it directly.
|
|
19
19
|
*/
|
|
20
|
+
import { handleOAuthClient, silentOffCookie } from './oauth-client.js';
|
|
21
|
+
const TOKEN_PATH = '/auth/oauth2/token';
|
|
20
22
|
const APP_ID_PATTERN = /^[a-z][a-z0-9-]{1,31}$/;
|
|
21
23
|
function normalizePrefix(prefix) {
|
|
22
24
|
if (!prefix)
|
|
@@ -33,10 +35,17 @@ function matchesPrefix(pathname, prefix) {
|
|
|
33
35
|
* Build the request forwarded to the gateway: same method/body/headers, with
|
|
34
36
|
* `X-Edge-Gate` attached. The path is preserved (the gateway derives + strips scope).
|
|
35
37
|
*/
|
|
36
|
-
function buildGatewayRequest(request,
|
|
38
|
+
function buildGatewayRequest(request, secrets, targetUrl) {
|
|
37
39
|
const headers = new Headers(request.headers);
|
|
38
|
-
if (edgeGateSecret)
|
|
39
|
-
headers.set('X-Edge-Gate', edgeGateSecret);
|
|
40
|
+
if (secrets.edgeGateSecret)
|
|
41
|
+
headers.set('X-Edge-Gate', secrets.edgeGateSecret);
|
|
42
|
+
// Only this proxy speaks for the origin: drop whatever the client sent.
|
|
43
|
+
headers.delete('X-Auth-Origin');
|
|
44
|
+
headers.delete('X-Origin-Stamp');
|
|
45
|
+
if (secrets.originStampSecret) {
|
|
46
|
+
headers.set('X-Auth-Origin', new URL(request.url).origin);
|
|
47
|
+
headers.set('X-Origin-Stamp', secrets.originStampSecret);
|
|
48
|
+
}
|
|
40
49
|
const init = {
|
|
41
50
|
method: request.method,
|
|
42
51
|
headers,
|
|
@@ -67,29 +76,90 @@ export function createAuthProxy(options) {
|
|
|
67
76
|
if (!options.gateway && !options.gatewayUrl) {
|
|
68
77
|
throw new Error('createAuthProxy: provide either `gateway` (Service Binding) or `gatewayUrl`.');
|
|
69
78
|
}
|
|
79
|
+
const { oauthClient, originStampSecret } = options;
|
|
80
|
+
const crossOriginPaths = (options.crossOriginPaths ?? []).map((p) => p.replace(/\/+$/, ''));
|
|
81
|
+
if (oauthClient && (!scope || !originStampSecret)) {
|
|
82
|
+
throw new Error('createAuthProxy: oauthClient needs `scope` and `originStampSecret`.');
|
|
83
|
+
}
|
|
84
|
+
/** Send a request to the gateway on `path` of the scope. */
|
|
85
|
+
const forward = (request, path, search) => {
|
|
86
|
+
// Scope enforcement: prepend the locked scope segment so the gateway always sees
|
|
87
|
+
// `/{scope}{path}`. `path` is already normalized (`..` collapsed) by URL, so the
|
|
88
|
+
// client can't smuggle a different scope past this. When no scope is locked the path
|
|
89
|
+
// is forwarded unchanged (the client carries its own scope segment — legacy).
|
|
90
|
+
const forwardPath = scope ? `/${scope}${path}` : path;
|
|
91
|
+
if (options.gateway) {
|
|
92
|
+
// Service Binding path — forward to the bound worker on the (rewritten) path.
|
|
93
|
+
const target = new URL(request.url);
|
|
94
|
+
target.pathname = forwardPath;
|
|
95
|
+
target.search = search;
|
|
96
|
+
return options.gateway.fetch(buildGatewayRequest(request, options, target.toString()));
|
|
97
|
+
}
|
|
98
|
+
// HTTP path — rebuild against the gateway origin, preserving the (rewritten) path + query.
|
|
99
|
+
const target = new URL(`${options.gatewayUrl.replace(/\/$/, '')}${forwardPath}`);
|
|
100
|
+
target.search = search;
|
|
101
|
+
return fetch(buildGatewayRequest(request, options, target.toString()));
|
|
102
|
+
};
|
|
103
|
+
/** The token request: stamped with this site's origin, carrying none of the browser's cookies. */
|
|
104
|
+
const exchange = (request, form) => {
|
|
105
|
+
const headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' });
|
|
106
|
+
for (const name of ['user-agent', 'accept-language', 'cf-connecting-ip']) {
|
|
107
|
+
const value = request.headers.get(name);
|
|
108
|
+
if (value)
|
|
109
|
+
headers.set(name, value);
|
|
110
|
+
}
|
|
111
|
+
const url = new URL(TOKEN_PATH, request.url);
|
|
112
|
+
return forward(new Request(url, { method: 'POST', headers, body: form.toString() }), TOKEN_PATH, '');
|
|
113
|
+
};
|
|
70
114
|
return async (request) => {
|
|
71
115
|
const url = new URL(request.url);
|
|
116
|
+
if (oauthClient && originStampSecret) {
|
|
117
|
+
const answer = await handleOAuthClient(request, {
|
|
118
|
+
resolve: oauthClient,
|
|
119
|
+
loginPath: options.loginPath ?? '/auth/login',
|
|
120
|
+
callbackPath: options.callbackPath ?? '/auth/callback',
|
|
121
|
+
silentStartPath: options.silentStartPath ?? '/auth/silent/start',
|
|
122
|
+
silentFinishPath: options.silentFinishPath ?? '/auth/silent/finish',
|
|
123
|
+
secret: originStampSecret,
|
|
124
|
+
exchange,
|
|
125
|
+
});
|
|
126
|
+
if (answer)
|
|
127
|
+
return answer;
|
|
128
|
+
// Only this proxy redeems codes: a page that could would be a client of its own.
|
|
129
|
+
if (url.pathname.replace(/\/+$/, '').endsWith(TOKEN_PATH))
|
|
130
|
+
return new Response(null, { status: 404 });
|
|
131
|
+
}
|
|
72
132
|
if (!matchesPrefix(url.pathname, prefix)) {
|
|
73
133
|
return passthrough(request);
|
|
74
134
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// path is forwarded unchanged (the client carries its own scope segment — legacy).
|
|
79
|
-
const forwardPath = scope ? `/${scope}${url.pathname}` : url.pathname;
|
|
80
|
-
// Service Binding path — forward to the bound worker on the (rewritten) path.
|
|
81
|
-
if (options.gateway) {
|
|
82
|
-
const target = new URL(url);
|
|
83
|
-
target.pathname = forwardPath;
|
|
84
|
-
const forwarded = buildGatewayRequest(request, options.edgeGateSecret, target.toString());
|
|
85
|
-
return options.gateway.fetch(forwarded);
|
|
135
|
+
const path = url.pathname.replace(/\/+$/, '');
|
|
136
|
+
if (options.allowedPaths && !options.allowedPaths.includes(path)) {
|
|
137
|
+
return new Response(null, { status: 404 });
|
|
86
138
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
139
|
+
if (crossOriginPaths.includes(path))
|
|
140
|
+
return forward(request, url.pathname, url.search);
|
|
141
|
+
// No Origin: a navigation or a same-origin GET, which no other origin can read.
|
|
142
|
+
const origin = request.headers.get('Origin');
|
|
143
|
+
if (origin !== null && origin !== url.origin)
|
|
144
|
+
return new Response(null, { status: 403 });
|
|
145
|
+
const answer = withoutCors(await forward(request, url.pathname, url.search));
|
|
146
|
+
// Signed out here: silent sign-in stays off until the customer signs in by clicking.
|
|
147
|
+
if (oauthClient && request.method === 'POST' && path.endsWith('/auth/logout') && answer.ok) {
|
|
148
|
+
const out = new Response(answer.body, answer);
|
|
149
|
+
out.headers.append('Set-Cookie', silentOffCookie(url));
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
return answer;
|
|
93
153
|
};
|
|
94
154
|
}
|
|
155
|
+
/** The answer without any CORS grant: this origin's pages need none, other origins get none. */
|
|
156
|
+
function withoutCors(response) {
|
|
157
|
+
const names = [...response.headers.keys()].filter((name) => name.toLowerCase().startsWith('access-control-'));
|
|
158
|
+
if (names.length === 0)
|
|
159
|
+
return response;
|
|
160
|
+
const out = new Response(response.body, response);
|
|
161
|
+
for (const name of names)
|
|
162
|
+
out.headers.delete(name);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
95
165
|
//# sourceMappingURL=proxy.js.map
|
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,iBAAiB,EAA4B,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAajG,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAExC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAkHhD,SAAS,eAAe,CAAC,MAA0B;IACjD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;IACzD,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,M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M,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,SAAS,WAAW,CAAC,QAAkB;IACrC,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC9G,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACxC,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-craft/pages-auth-proxy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Thin Cloudflare Pages reverse-proxy for Auth Craft — serves /{scope}/auth/* same-origin (first-party cookies) and forwards to the gateway worker (Service Binding or HTTP + X-Edge-Gate). Keeps all trust-critical logic in the gateway.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|