@softure-ai/auth 0.2.7 → 0.2.9

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/README.md +62 -2
  3. package/dist/index.d.ts +44 -9
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/options.d.ts +124 -13
  8. package/dist/options.d.ts.map +1 -1
  9. package/dist/options.js +48 -15
  10. package/dist/options.js.map +1 -1
  11. package/dist/server/oidc/allowlist.d.ts +10 -0
  12. package/dist/server/oidc/allowlist.d.ts.map +1 -0
  13. package/dist/server/oidc/allowlist.js +23 -0
  14. package/dist/server/oidc/allowlist.js.map +1 -0
  15. package/dist/server/oidc/discovery.d.ts +2 -2
  16. package/dist/server/oidc/discovery.d.ts.map +1 -1
  17. package/dist/server/oidc/discovery.js.map +1 -1
  18. package/dist/server/oidc/flow.d.ts +0 -7
  19. package/dist/server/oidc/flow.d.ts.map +1 -1
  20. package/dist/server/oidc/flow.js +50 -49
  21. package/dist/server/oidc/flow.js.map +1 -1
  22. package/dist/server/oidc/github.d.ts +33 -0
  23. package/dist/server/oidc/github.d.ts.map +1 -0
  24. package/dist/server/oidc/github.js +92 -0
  25. package/dist/server/oidc/github.js.map +1 -0
  26. package/dist/server/oidc/index.d.ts +2 -1
  27. package/dist/server/oidc/index.d.ts.map +1 -1
  28. package/dist/server/oidc/index.js +3 -2
  29. package/dist/server/oidc/index.js.map +1 -1
  30. package/dist/server/oidc/token-request.d.ts +2 -2
  31. package/dist/server/oidc/token-request.d.ts.map +1 -1
  32. package/dist/testing/github-provider.d.ts +58 -0
  33. package/dist/testing/github-provider.d.ts.map +1 -0
  34. package/dist/testing/github-provider.js +139 -0
  35. package/dist/testing/github-provider.js.map +1 -0
  36. package/dist/testing/index.d.ts +1 -0
  37. package/dist/testing/index.d.ts.map +1 -1
  38. package/dist/testing/index.js +2 -1
  39. package/dist/testing/index.js.map +1 -1
  40. package/dist/testing/oidc-provider.d.ts +2 -2
  41. package/dist/testing/oidc-provider.d.ts.map +1 -1
  42. package/module.json +1 -1
  43. package/package.json +1 -1
  44. package/src/index.ts +7 -2
  45. package/src/options.ts +80 -36
  46. package/src/server/oidc/allowlist.ts +23 -0
  47. package/src/server/oidc/discovery.ts +2 -2
  48. package/src/server/oidc/flow.ts +63 -47
  49. package/src/server/oidc/github.ts +112 -0
  50. package/src/server/oidc/index.ts +2 -2
  51. package/src/server/oidc/token-request.ts +2 -2
  52. package/src/testing/github-provider.ts +202 -0
  53. package/src/testing/index.ts +10 -1
  54. package/src/testing/oidc-provider.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,38 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
6
6
 
7
+ ## 0.2.9
8
+
9
+ - Sign in with GitHub (#840): a provider entry `{ type: "github", id, name, clientIdEnv, clientSecretEnv,
10
+ allowedEmails | allowedDomains }` in `oidc.providers`. GitHub is an OAuth App, not OpenID Connect: the endpoints are
11
+ fixed, and the account is read from GitHub's API (`/user`, `/user/emails`) with an access token that is never
12
+ stored. The subject is the numeric account id; only verified emails count, primary first. Everything else is the
13
+ OpenID Connect sign-in's: state, PKCE, cookie, `oidc-*` buckets, callback route, allowlist, `auth.identities`,
14
+ linking, `onRegistered`, error codes. `createFakeGithubProvider` in `@softure-ai/auth/testing` tests it without
15
+ network. README section 3, "GitHub sign-in".
16
+ - Types: `OidcProvider` is now a union of `OpenIdConnectProvider` (`type: "oidc"`, the default for an entry without
17
+ `type`) and `GithubProvider`; code that reads `provider.issuer` narrows on `type` first. The parsed options carry
18
+ `type`. New exports: `OpenIdConnectProvider`, `OpenIdConnectProviderInput`, `GithubProvider`, `GithubProviderInput`.
19
+ - The allowlist message reads "a sign-in through a provider is limited to them".
20
+
21
+ No change for an app: existing entries parse as before, no migration, bucket, route or copy is added. Sign-in through
22
+ a provider stays opt-in.
23
+
24
+ ## 0.2.8
25
+
26
+ - OpenID Connect stays opt-in, now stated and tested (#786). An app without `oidc.providers` runs none of it. On a bump
27
+ past 0.2.5 such an app still gets two empty tables (`auth.identities`, `auth.oidc_states`, migration `0005`): a
28
+ module's migrations are one numbered sequence and cannot depend on its options, and without a provider nothing
29
+ writes to them. The `oidc-start` and `oidc-callback` buckets are required only with a provider; spreading
30
+ `AUTH_RATE_LIMIT_BUCKETS` adds their definitions, which count nothing. A new test pins it: without a provider and
31
+ without those buckets, registration and login work and no OpenID Connect row is written. README section 3,
32
+ "Without a provider", lists it all.
33
+ - The 0.2.6 entry below is corrected: it called the release additive without naming migration `0005` or the copy
34
+ keys that 0.2.6 required (optional since 0.2.7).
35
+
36
+ Steps for an app without a provider, from any version up to 0.2.5 to this one: run `softure migrate` (migrations
37
+ `0005` and `0006`). Nothing else: no copy, buckets, environment variables or routes to add.
38
+
7
39
  ## 0.2.7
8
40
 
9
41
  - `AuthMessages`: the OpenID Connect keys (`oidc`, `errors.auth.oidc_failed`, `oidc_cancelled`, `oidc_not_allowed`,
@@ -27,8 +59,10 @@ Migration for an app: run `softure migrate` (migration `0006`). To show the sign
27
59
 
28
60
  ## 0.2.6
29
61
 
30
- Sign in with an OpenID Connect provider (Google), limited to allowed domains or emails (#769). Additive: an app without
31
- `oidc` sees no change except two new bucket defaults.
62
+ Sign in with an OpenID Connect provider (Google), limited to allowed domains or emails (#769). Opt-in, but not
63
+ additive for every app: an app without `oidc` runs migration `0005` (two tables it leaves empty), and an app with its
64
+ own dictionary typed `AuthMessages` must add the OpenID Connect copy keys (optional again in 0.2.7). The two new bucket
65
+ defaults are required only with a provider.
32
66
 
33
67
  - `auth({ oidc: { providers: [{ id, name, issuer, clientIdEnv, clientSecretEnv, allowedDomains, allowedEmails,
34
68
  createAccounts, ... }] } })`: authorization code flow with PKCE S256, a one-time state bound to the browser by a
package/README.md CHANGED
@@ -123,13 +123,13 @@ passwords for one email, from any addresses, block logins to that account for th
123
123
  window, the owner's included. Raise its limit if that trade-off is wrong for your app. Auth checks
124
124
  at its first call that the buckets it counts in exist and names the missing ones: the three
125
125
  `password-reset*` buckets only when `passwordReset.send` is set, `oidc-start` and `oidc-callback` (per client address)
126
- only with an OpenID Connect provider. A request whose client address
126
+ only with a provider (OpenID Connect or GitHub). A request whose client address
127
127
  cannot be resolved is refused (`security.client_unidentified`); the security README shows resolver
128
128
  chains for production and for development and test stacks.
129
129
 
130
130
  ### OpenID Connect sign-in
131
131
 
132
- Sign in with Google, or any OpenID Connect provider, for the accounts of a Workspace domain or a short list of
132
+ Sign in with Google, or any OpenID Connect provider (or GitHub, below), for the accounts of a Workspace domain or a short list of
133
133
  emails. Off without providers. With `password: { enabled: false }` it is the only way in: no password, no
134
134
  registration form, no outer sign-in in front of the host.
135
135
 
@@ -201,6 +201,66 @@ the variables the provider names.
201
201
  `oidc.fetch` and `fake.env` as the context's `env`; `fake.signIn(authorizeUrl, { subject, email, hostedDomain, name, givenName })`
202
202
  answers the callback URL. It can break on purpose (`claims`, `signWith`, `rotateKeys`, `failNext`, `setDiscovery`).
203
203
 
204
+ #### GitHub sign-in
205
+
206
+ GitHub is not an OpenID Connect provider for people (an OAuth App has no discovery document, ID token or keys), so it
207
+ is a provider type of its own in the same list. It shares the button, the route, the cookie, the state and PKCE, the
208
+ `oidc-*` buckets, the allowlist, `auth.identities`, account linking, `onRegistered` and the error codes above; only the
209
+ protocol step differs.
210
+
211
+ ```ts
212
+ auth({
213
+ password: { enabled: false },
214
+ oidc: {
215
+ providers: [
216
+ {
217
+ type: "github", // no issuer: GitHub's endpoints are fixed
218
+ id: "github", // the callback is /api/auth/oidc/github/callback
219
+ name: "GitHub",
220
+ clientIdEnv: "GITHUB_AUTH_CLIENT_ID",
221
+ clientSecretEnv: "GITHUB_AUTH_CLIENT_SECRET", // required: GitHub's token endpoint always needs it
222
+ allowedEmails: ["owner@example.com"], // or allowedDomains
223
+ authorizeParams: { allow_signup: "false" }, // optional, sent as they are
224
+ },
225
+ ],
226
+ },
227
+ });
228
+ ```
229
+
230
+ At GitHub, create an OAuth App (Settings, Developer settings, OAuth Apps), set its "Authorization callback URL" to
231
+ `<appOrigin>/api/auth/oidc/<id>/callback` and put its client id and a client secret in the variables above.
232
+
233
+ - **Flow.** The browser goes to `https://github.com/login/oauth/authorize` with the scopes `read:user user:email`, the
234
+ state and the PKCE S256 challenge (no nonce). The callback exchanges the code at
235
+ `https://github.com/login/oauth/access_token` (GitHub answers an OAuth error with status 200, which still fails the
236
+ sign-in), then reads `GET https://api.github.com/user` and `GET https://api.github.com/user/emails` with the access
237
+ token. The token is used for those two reads only: it is never stored or logged.
238
+ - **Who may sign in.** Only verified emails count. The primary email is tried first, then any other verified email,
239
+ and the first one that `allowedEmails` or `allowedDomains` accepts signs in (there is no hosted domain on GitHub).
240
+ None: `auth.oidc_not_allowed`.
241
+ - **Accounts.** The subject is the numeric GitHub account id, so a renamed login or a changed email keeps the account.
242
+ The display name is the profile `name`, else the `login`. The log line reads `GitHub sign-in with github failed: …`.
243
+ - **Tests.** `createFakeGithubProvider()` from `@softure-ai/auth/testing` is GitHub in memory (authorize check, token
244
+ endpoint with PKCE and one-time codes, `/user`, `/user/emails`): pass `fake.definition`, `fake.fetch` and `fake.env`
245
+ as with the OpenID Connect fake; `fake.signIn(authorizeUrl, { id, login, name, emails: [{ email, verified, primary }] })`
246
+ answers the callback URL, `{ deny: true }` a refusal, and `failNext` breaks the next calls
247
+ (`unavailable`, `bad_verification_code`, `user_unavailable`, `emails_unavailable`).
248
+
249
+ **Without a provider.** OpenID Connect is opt-in: an app chooses its sign-in methods, and with no
250
+ `oidc.providers` nothing of it runs. What such an app still gets, and why it needs nothing:
251
+
252
+ - **Tables.** `softure migrate` creates `auth.identities` and `auth.oidc_states` for every app (migration `0005`):
253
+ a module's migrations run in one numbered sequence and cannot depend on its options. Without a provider nothing
254
+ writes to them; they stay empty. The privacy export and deletion read them by user and find nothing.
255
+ - **Rate limit buckets.** `oidc-start` and `oidc-callback` are required only with a provider. Spreading
256
+ `AUTH_RATE_LIMIT_BUCKETS` adds their definitions, which count nothing until a sign-in starts; an app that lists its
257
+ buckets by hand leaves them out.
258
+ - **Copy.** The `oidc` copy and the `errors.auth.oidc_*` codes are optional in `AuthMessages` (section 9); a
259
+ dictionary without them compiles.
260
+ - **Routes.** `app/api/auth/oidc/[provider]/callback/route.ts` is needed only with a provider; leave it unmounted.
261
+
262
+ The one step on a bump past 0.2.5: run `softure migrate`, as for any release with a migration.
263
+
204
264
  ## 4. Mounting
205
265
 
206
266
  One line per file, owned by the app (docs/02 §8):
package/dist/index.d.ts CHANGED
@@ -11,7 +11,8 @@ export declare const REGISTRATION_CLOSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION
11
11
  * `register` and `login` per client address, `login-account` per email, `change-password` per user,
12
12
  * `password-reset` (link requests) and `password-reset-confirm` (new passwords) per client address,
13
13
  * `password-reset-account` per email, which bounds the mails one address can receive, and `oidc-start` and
14
- * `oidc-callback` (OpenID Connect sign-ins started and completed) per client address.
14
+ * `oidc-callback` (OpenID Connect sign-ins started and completed) per client address. The `oidc-*` buckets are
15
+ * required only with a provider and count nothing without one, so an app without OpenID Connect may leave them out.
15
16
  */
16
17
  export declare const AUTH_RATE_LIMIT_BUCKETS: {
17
18
  readonly register: {
@@ -208,7 +209,12 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
208
209
  ttlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
209
210
  }, import("zod/v4/core").$strict>>;
210
211
  oidc: import("zod").ZodPrefault<import("zod").ZodObject<{
211
- providers: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodObject<{
212
+ providers: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
213
+ requireHostedDomain: import("zod").ZodOptional<import("zod").ZodBoolean>;
214
+ allowedDomains: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
215
+ allowedEmails: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>>;
216
+ createAccounts: import("zod").ZodDefault<import("zod").ZodBoolean>;
217
+ type: import("zod").ZodDefault<import("zod").ZodLiteral<"oidc">>;
212
218
  id: import("zod").ZodString;
213
219
  name: import("zod").ZodString;
214
220
  issuer: import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string, string>>;
@@ -220,12 +226,33 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
220
226
  }>>;
221
227
  scopes: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
222
228
  authorizeParams: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
229
+ }, import("zod/v4/core").$strict>, import("zod").ZodObject<{
223
230
  allowedDomains: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
224
231
  allowedEmails: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>>;
225
- requireHostedDomain: import("zod").ZodOptional<import("zod").ZodBoolean>;
226
232
  createAccounts: import("zod").ZodDefault<import("zod").ZodBoolean>;
227
- }, import("zod/v4/core").$strict>, import("zod").ZodTransform<{
233
+ type: import("zod").ZodLiteral<"github">;
234
+ id: import("zod").ZodString;
235
+ name: import("zod").ZodString;
236
+ clientIdEnv: import("zod").ZodString;
237
+ clientSecretEnv: import("zod").ZodString;
238
+ authorizeParams: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
239
+ }, import("zod/v4/core").$strict>], "type">, import("zod").ZodTransform<{
240
+ requireHostedDomain: false;
241
+ allowedDomains: string[];
242
+ allowedEmails: string[];
243
+ createAccounts: boolean;
244
+ type: "github";
245
+ id: string;
246
+ name: string;
247
+ clientIdEnv: string;
248
+ clientSecretEnv: string;
249
+ authorizeParams: Record<string, string>;
250
+ } | {
228
251
  requireHostedDomain: boolean;
252
+ allowedDomains: string[];
253
+ allowedEmails: string[];
254
+ createAccounts: boolean;
255
+ type: "oidc";
229
256
  id: string;
230
257
  name: string;
231
258
  issuer: string;
@@ -233,11 +260,12 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
233
260
  clientAuth: "body" | "basic";
234
261
  scopes: string[];
235
262
  authorizeParams: Record<string, string>;
263
+ clientSecretEnv?: string | undefined;
264
+ }, {
236
265
  allowedDomains: string[];
237
266
  allowedEmails: string[];
238
267
  createAccounts: boolean;
239
- clientSecretEnv?: string | undefined;
240
- }, {
268
+ type: "oidc";
241
269
  id: string;
242
270
  name: string;
243
271
  issuer: string;
@@ -245,11 +273,18 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
245
273
  clientAuth: "body" | "basic";
246
274
  scopes: string[];
247
275
  authorizeParams: Record<string, string>;
276
+ requireHostedDomain?: boolean | undefined;
277
+ clientSecretEnv?: string | undefined;
278
+ } | {
248
279
  allowedDomains: string[];
249
280
  allowedEmails: string[];
250
281
  createAccounts: boolean;
251
- clientSecretEnv?: string | undefined;
252
- requireHostedDomain?: boolean | undefined;
282
+ type: "github";
283
+ id: string;
284
+ name: string;
285
+ clientIdEnv: string;
286
+ clientSecretEnv: string;
287
+ authorizeParams: Record<string, string>;
253
288
  }>>>>;
254
289
  stateTtlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
255
290
  httpTimeoutMs: import("zod").ZodDefault<import("zod").ZodNumber>;
@@ -261,7 +296,7 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
261
296
  export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
262
297
  export type { AuthErrorCode, AuthFormErrorCode, AuthFormField, AuthFormState, AuthUser, NewSession, OidcSignInErrorCode, RegisteredEvent, SignedIn, } from "./contract.js";
263
298
  export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
264
- export { OIDC_PROVIDER_ID_PATTERN, type AuthOptions, type AuthOptionsInput, type OidcProvider, type OidcProviderInput, type OnRegisteredHook, type RewriteRedirect, type RewriteRedirectContext, type ScryptParams, } from "./options.js";
299
+ export { OIDC_PROVIDER_ID_PATTERN, type AuthOptions, type AuthOptionsInput, type GithubProvider, type GithubProviderInput, type OidcProvider, type OidcProviderInput, type OnRegisteredHook, type OpenIdConnectProvider, type OpenIdConnectProviderInput, type RewriteRedirect, type RewriteRedirectContext, type ScryptParams, } from "./options.js";
265
300
  export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetEnqueuer, type PasswordResetSender, } from "./password-reset-sender.js";
266
301
  export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
267
302
  export { toSafeNextPath } from "./safe-next-path.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AAEjF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAU+B,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAyCf,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EACV,aAAa,EACb,iBAAi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 +19,8 @@ export const REGISTRATION_CLOSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED"
19
19
  * `register` and `login` per client address, `login-account` per email, `change-password` per user,
20
20
  * `password-reset` (link requests) and `password-reset-confirm` (new passwords) per client address,
21
21
  * `password-reset-account` per email, which bounds the mails one address can receive, and `oidc-start` and
22
- * `oidc-callback` (OpenID Connect sign-ins started and completed) per client address.
22
+ * `oidc-callback` (OpenID Connect sign-ins started and completed) per client address. The `oidc-*` buckets are
23
+ * required only with a provider and count nothing without one, so an app without OpenID Connect may leave them out.
23
24
  */
24
25
  export const AUTH_RATE_LIMIT_BUCKETS = {
25
26
  register: { limit: 5, windowMinutes: 15, key: "ip" },
@@ -39,7 +40,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
39
40
  export const auth = defineModule({
40
41
  manifest: {
41
42
  id: MODULE_ID,
42
- version: "0.2.7",
43
+ version: "0.2.9",
43
44
  dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?", jobs: "^0.1.1?" },
44
45
  dbSchema: "auth",
45
46
  tables: ["users", "sessions", "user_roles", "password_resets", "identities", "oidc_states"],
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,qIAAqI;AACrI,sGAAsG;AACtG,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEhC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,0BAA0B,GAAG,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,EAAE;YAC9G,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE;SACpE;QACD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;KAC1C;IACD,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,iBAAiB;IAC1B,UAAU,EAAE,EAAE,GAAG,EAAE,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;IAC5E,OAAO,EAAE,sBAAsB;IAC/B,MAAM,EAAE,eAAe;CACxB,CAAC,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAYxD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,wBAAwB,GAazB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,0BAA0B,GAI3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
package/dist/options.d.ts CHANGED
@@ -36,7 +36,12 @@ declare const scryptSchema: z.ZodObject<{
36
36
  export declare const OIDC_PROVIDER_ID_PATTERN: RegExp;
37
37
  /** An https URL, or http on the local machine (a development identity provider). */
38
38
  export declare function isSecureEndpoint(value: string): boolean;
39
- declare const oidcProviderSchema: z.ZodPipe<z.ZodObject<{
39
+ declare const openIdConnectProviderSchema: z.ZodObject<{
40
+ requireHostedDomain: z.ZodOptional<z.ZodBoolean>;
41
+ allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
42
+ allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
43
+ createAccounts: z.ZodDefault<z.ZodBoolean>;
44
+ type: z.ZodDefault<z.ZodLiteral<"oidc">>;
40
45
  id: z.ZodString;
41
46
  name: z.ZodString;
42
47
  issuer: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -48,12 +53,67 @@ declare const oidcProviderSchema: z.ZodPipe<z.ZodObject<{
48
53
  }>>;
49
54
  scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
50
55
  authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
56
+ }, z.core.$strict>;
57
+ /**
58
+ * Sign-in with a GitHub OAuth App: not OpenID Connect (no discovery, ID token or keys), so the endpoints are fixed and
59
+ * the account is read from GitHub's API with the access token, which is not kept. Everything around it (state, PKCE,
60
+ * cookie, rate limits, callback route, allowlist, identities) is the OpenID Connect sign-in's.
61
+ */
62
+ declare const githubProviderSchema: z.ZodObject<{
51
63
  allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
52
64
  allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
65
+ createAccounts: z.ZodDefault<z.ZodBoolean>;
66
+ type: z.ZodLiteral<"github">;
67
+ id: z.ZodString;
68
+ name: z.ZodString;
69
+ clientIdEnv: z.ZodString;
70
+ clientSecretEnv: z.ZodString;
71
+ authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
72
+ }, z.core.$strict>;
73
+ declare const oidcProviderSchema: z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
53
74
  requireHostedDomain: z.ZodOptional<z.ZodBoolean>;
75
+ allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
76
+ allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
54
77
  createAccounts: z.ZodDefault<z.ZodBoolean>;
55
- }, z.core.$strict>, z.ZodTransform<{
78
+ type: z.ZodDefault<z.ZodLiteral<"oidc">>;
79
+ id: z.ZodString;
80
+ name: z.ZodString;
81
+ issuer: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
82
+ clientIdEnv: z.ZodString;
83
+ clientSecretEnv: z.ZodOptional<z.ZodString>;
84
+ clientAuth: z.ZodDefault<z.ZodEnum<{
85
+ body: "body";
86
+ basic: "basic";
87
+ }>>;
88
+ scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
89
+ authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
90
+ }, z.core.$strict>, z.ZodObject<{
91
+ allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
92
+ allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
93
+ createAccounts: z.ZodDefault<z.ZodBoolean>;
94
+ type: z.ZodLiteral<"github">;
95
+ id: z.ZodString;
96
+ name: z.ZodString;
97
+ clientIdEnv: z.ZodString;
98
+ clientSecretEnv: z.ZodString;
99
+ authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
100
+ }, z.core.$strict>], "type">, z.ZodTransform<{
101
+ requireHostedDomain: false;
102
+ allowedDomains: string[];
103
+ allowedEmails: string[];
104
+ createAccounts: boolean;
105
+ type: "github";
106
+ id: string;
107
+ name: string;
108
+ clientIdEnv: string;
109
+ clientSecretEnv: string;
110
+ authorizeParams: Record<string, string>;
111
+ } | {
56
112
  requireHostedDomain: boolean;
113
+ allowedDomains: string[];
114
+ allowedEmails: string[];
115
+ createAccounts: boolean;
116
+ type: "oidc";
57
117
  id: string;
58
118
  name: string;
59
119
  issuer: string;
@@ -61,11 +121,12 @@ declare const oidcProviderSchema: z.ZodPipe<z.ZodObject<{
61
121
  clientAuth: "body" | "basic";
62
122
  scopes: string[];
63
123
  authorizeParams: Record<string, string>;
124
+ clientSecretEnv?: string | undefined;
125
+ }, {
64
126
  allowedDomains: string[];
65
127
  allowedEmails: string[];
66
128
  createAccounts: boolean;
67
- clientSecretEnv?: string | undefined;
68
- }, {
129
+ type: "oidc";
69
130
  id: string;
70
131
  name: string;
71
132
  issuer: string;
@@ -73,14 +134,30 @@ declare const oidcProviderSchema: z.ZodPipe<z.ZodObject<{
73
134
  clientAuth: "body" | "basic";
74
135
  scopes: string[];
75
136
  authorizeParams: Record<string, string>;
137
+ requireHostedDomain?: boolean | undefined;
138
+ clientSecretEnv?: string | undefined;
139
+ } | {
76
140
  allowedDomains: string[];
77
141
  allowedEmails: string[];
78
142
  createAccounts: boolean;
79
- clientSecretEnv?: string | undefined;
80
- requireHostedDomain?: boolean | undefined;
143
+ type: "github";
144
+ id: string;
145
+ name: string;
146
+ clientIdEnv: string;
147
+ clientSecretEnv: string;
148
+ authorizeParams: Record<string, string>;
81
149
  }>>;
82
150
  export type OidcProviderInput = z.input<typeof oidcProviderSchema>;
151
+ export type OpenIdConnectProviderInput = z.input<typeof openIdConnectProviderSchema>;
152
+ export type GithubProviderInput = z.input<typeof githubProviderSchema>;
153
+ /** A configured sign-in provider: OpenID Connect (`type: "oidc"`) or GitHub (`type: "github"`). */
83
154
  export type OidcProvider = z.output<typeof oidcProviderSchema>;
155
+ export type OpenIdConnectProvider = Extract<OidcProvider, {
156
+ readonly type: "oidc";
157
+ }>;
158
+ export type GithubProvider = Extract<OidcProvider, {
159
+ readonly type: "github";
160
+ }>;
84
161
  export declare const authOptionsSchema: z.ZodObject<{
85
162
  password: z.ZodPrefault<z.ZodObject<{
86
163
  enabled: z.ZodDefault<z.ZodBoolean>;
@@ -114,7 +191,12 @@ export declare const authOptionsSchema: z.ZodObject<{
114
191
  ttlMinutes: z.ZodDefault<z.ZodNumber>;
115
192
  }, z.core.$strict>>;
116
193
  oidc: z.ZodPrefault<z.ZodObject<{
117
- providers: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodObject<{
194
+ providers: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
195
+ requireHostedDomain: z.ZodOptional<z.ZodBoolean>;
196
+ allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
197
+ allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
198
+ createAccounts: z.ZodDefault<z.ZodBoolean>;
199
+ type: z.ZodDefault<z.ZodLiteral<"oidc">>;
118
200
  id: z.ZodString;
119
201
  name: z.ZodString;
120
202
  issuer: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -126,12 +208,33 @@ export declare const authOptionsSchema: z.ZodObject<{
126
208
  }>>;
127
209
  scopes: z.ZodDefault<z.ZodArray<z.ZodString>>;
128
210
  authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
211
+ }, z.core.$strict>, z.ZodObject<{
129
212
  allowedDomains: z.ZodDefault<z.ZodArray<z.ZodString>>;
130
213
  allowedEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
131
- requireHostedDomain: z.ZodOptional<z.ZodBoolean>;
132
214
  createAccounts: z.ZodDefault<z.ZodBoolean>;
133
- }, z.core.$strict>, z.ZodTransform<{
215
+ type: z.ZodLiteral<"github">;
216
+ id: z.ZodString;
217
+ name: z.ZodString;
218
+ clientIdEnv: z.ZodString;
219
+ clientSecretEnv: z.ZodString;
220
+ authorizeParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
221
+ }, z.core.$strict>], "type">, z.ZodTransform<{
222
+ requireHostedDomain: false;
223
+ allowedDomains: string[];
224
+ allowedEmails: string[];
225
+ createAccounts: boolean;
226
+ type: "github";
227
+ id: string;
228
+ name: string;
229
+ clientIdEnv: string;
230
+ clientSecretEnv: string;
231
+ authorizeParams: Record<string, string>;
232
+ } | {
134
233
  requireHostedDomain: boolean;
234
+ allowedDomains: string[];
235
+ allowedEmails: string[];
236
+ createAccounts: boolean;
237
+ type: "oidc";
135
238
  id: string;
136
239
  name: string;
137
240
  issuer: string;
@@ -139,11 +242,12 @@ export declare const authOptionsSchema: z.ZodObject<{
139
242
  clientAuth: "body" | "basic";
140
243
  scopes: string[];
141
244
  authorizeParams: Record<string, string>;
245
+ clientSecretEnv?: string | undefined;
246
+ }, {
142
247
  allowedDomains: string[];
143
248
  allowedEmails: string[];
144
249
  createAccounts: boolean;
145
- clientSecretEnv?: string | undefined;
146
- }, {
250
+ type: "oidc";
147
251
  id: string;
148
252
  name: string;
149
253
  issuer: string;
@@ -151,11 +255,18 @@ export declare const authOptionsSchema: z.ZodObject<{
151
255
  clientAuth: "body" | "basic";
152
256
  scopes: string[];
153
257
  authorizeParams: Record<string, string>;
258
+ requireHostedDomain?: boolean | undefined;
259
+ clientSecretEnv?: string | undefined;
260
+ } | {
154
261
  allowedDomains: string[];
155
262
  allowedEmails: string[];
156
263
  createAccounts: boolean;
157
- clientSecretEnv?: string | undefined;
158
- requireHostedDomain?: boolean | undefined;
264
+ type: "github";
265
+ id: string;
266
+ name: string;
267
+ clientIdEnv: string;
268
+ clientSecretEnv: string;
269
+ authorizeParams: Record<string, string>;
159
270
  }>>>>;
160
271
  stateTtlMinutes: z.ZodDefault<z.ZodNumber>;
161
272
  httpTimeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAG7F;;;;GAIG;AAC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:" || (url.protocol === "http:" && LOCAL_HOSTS.has(url.hostname));
75
75
  }
76
76
  const domainSchema = z.string().trim().toLowerCase().regex(DOMAIN, "must be a lowercase host name such as example.com");
77
- const oidcProviderSchema = z
78
- .strictObject({
77
+ /** Who may sign in through a provider; refined on every provider type. */
78
+ const allowlistShape = {
79
+ /** Who may sign in: a verified email in one of these domains. */
80
+ allowedDomains: z.array(domainSchema).default([]),
81
+ /** Who may sign in: one of these verified emails. */
82
+ allowedEmails: z.array(adminEmailSchema).default([]),
83
+ /** A first sign-in of an allowed identity without an account creates one (no password); false only links. */
84
+ createAccounts: z.boolean().default(true),
85
+ };
86
+ const providerIdSchema = z.string().regex(OIDC_PROVIDER_ID_PATTERN, "must be an id such as google (a-z first, then a-z, 0-9 or -, at most 32)");
87
+ const authorizeParamsSchema = z.record(z.string().regex(/^[a-z_]{1,64}$/), z.string().max(512)).default({});
88
+ const openIdConnectProviderSchema = z.strictObject({
89
+ /** Optional: an entry without `type` is an OpenID Connect provider. */
90
+ type: z.literal("oidc").default("oidc"),
79
91
  /** The provider's id in URLs and in `auth.identities`, e.g. `google`. */
80
- id: z.string().regex(OIDC_PROVIDER_ID_PATTERN, "must be an id such as google (a-z first, then a-z, 0-9 or -, at most 32)"),
92
+ id: providerIdSchema,
81
93
  /** The provider's name as the button shows it (`messages.oidc.signInWith`), e.g. `Google`. */
82
94
  name: z.string().trim().min(1).max(64),
83
95
  /** The issuer; its discovery document is `<issuer>/.well-known/openid-configuration`. */
@@ -94,22 +106,40 @@ const oidcProviderSchema = z
94
106
  /** Requested scopes; `openid` and `email` are always sent. */
95
107
  scopes: z.array(z.string().regex(/^[\x21\x23-\x5b\x5d-\x7e]{1,128}$/, "must be a scope token")).default([]),
96
108
  /** Extra parameters of the authorize URL, e.g. `{ prompt: "select_account", hd: "example.com" }`. */
97
- authorizeParams: z.record(z.string().regex(/^[a-z_]{1,64}$/), z.string().max(512)).default({}),
98
- /** Who may sign in: a verified email in one of these domains. */
99
- allowedDomains: z.array(domainSchema).default([]),
100
- /** Who may sign in: one of these verified emails. */
101
- allowedEmails: z.array(adminEmailSchema).default([]),
109
+ authorizeParams: authorizeParamsSchema,
110
+ ...allowlistShape,
102
111
  /**
103
112
  * A domain match also needs the token's `hd` claim to name that domain (a Google Workspace account). Defaults to
104
113
  * true for Google, whose consumer accounts can carry a verified address of any domain.
105
114
  */
106
115
  requireHostedDomain: z.boolean().optional(),
107
- /** A first sign-in of an allowed identity without an account creates one (no password); false only links. */
108
- createAccounts: z.boolean().default(true),
109
- })
110
- .transform((provider) => ({ ...provider, requireHostedDomain: provider.requireHostedDomain ?? provider.issuer === GOOGLE_ISSUER }))
116
+ });
117
+ /**
118
+ * Sign-in with a GitHub OAuth App: not OpenID Connect (no discovery, ID token or keys), so the endpoints are fixed and
119
+ * the account is read from GitHub's API with the access token, which is not kept. Everything around it (state, PKCE,
120
+ * cookie, rate limits, callback route, allowlist, identities) is the OpenID Connect sign-in's.
121
+ */
122
+ const githubProviderSchema = z.strictObject({
123
+ type: z.literal("github"),
124
+ /** The provider's id in URLs and in `auth.identities`, e.g. `github`. */
125
+ id: providerIdSchema,
126
+ /** The provider's name as the button shows it, e.g. `GitHub`. */
127
+ name: z.string().trim().min(1).max(64),
128
+ /** The environment variable that holds the OAuth App's client id. */
129
+ clientIdEnv: z.string().regex(ENV_NAME, "must be an environment variable name such as GITHUB_AUTH_CLIENT_ID"),
130
+ /** The environment variable that holds the OAuth App's client secret (GitHub's token endpoint always needs it). */
131
+ clientSecretEnv: z.string().regex(ENV_NAME, "must be an environment variable name such as GITHUB_AUTH_CLIENT_SECRET"),
132
+ /** Extra parameters of the authorize URL, e.g. `{ allow_signup: "false", prompt: "select_account" }`. */
133
+ authorizeParams: authorizeParamsSchema,
134
+ ...allowlistShape,
135
+ });
136
+ const oidcProviderSchema = z
137
+ .discriminatedUnion("type", [openIdConnectProviderSchema, githubProviderSchema])
138
+ .transform((provider) => provider.type === "github"
139
+ ? { ...provider, requireHostedDomain: false }
140
+ : { ...provider, requireHostedDomain: provider.requireHostedDomain ?? provider.issuer === GOOGLE_ISSUER })
111
141
  .refine((provider) => provider.allowedDomains.length + provider.allowedEmails.length > 0, {
112
- message: "needs allowedDomains or allowedEmails: an OpenID Connect sign-in is limited to them",
142
+ message: "needs allowedDomains or allowedEmails: a sign-in through a provider is limited to them",
113
143
  path: ["allowedDomains"],
114
144
  });
115
145
  export const authOptionsSchema = z.strictObject({
@@ -193,7 +223,10 @@ export const authOptionsSchema = z.strictObject({
193
223
  ttlMinutes: z.number().int().min(5).max(1440).default(60),
194
224
  })
195
225
  .prefault({}),
196
- /** Sign-in with OpenID Connect providers (e.g. Google), limited to allowed domains or emails. Off without providers. */
226
+ /**
227
+ * Sign-in with OpenID Connect providers (e.g. Google) or GitHub (`type: "github"`), limited to allowed domains or
228
+ * emails. Off without providers.
229
+ */
197
230
  oidc: z
198
231
  .strictObject({
199
232
  providers: z
@@ -202,7 +235,7 @@ export const authOptionsSchema = z.strictObject({
202
235
  .default([]),
203
236
  /** How long a started sign-in may take at the provider. */
204
237
  stateTtlMinutes: z.number().int().min(1).max(60).default(10),
205
- /** Timeout of each call to a provider (discovery, keys, token). */
238
+ /** Timeout of each call to a provider (discovery, keys, token, GitHub's API). */
206
239
  httpTimeoutMs: z.number().int().min(1000).max(60_000).default(10_000),
207
240
  /** The `fetch` the provider calls go through; tests pass a fake provider's. */
208
241
  fetch: z.custom((value) => typeof value === "function", "must be a function").optional(),