@pithy-sh/auth 0.2.1 → 0.3.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.
@@ -4,6 +4,7 @@ import type { Capability } from "@pithy-sh/core/src/capability/capability";
4
4
  import type { EmailCapability } from "@pithy-sh/email/src/capability";
5
5
  import { type TurnstileMode } from "@pithy-sh/turnstile/src/config/config";
6
6
  import { z } from "zod";
7
+ import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
7
8
  /** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
8
9
  export declare const AuthConfig: z.ZodObject<{
9
10
  basePath: z.ZodDefault<z.ZodString>;
@@ -11,17 +12,21 @@ export declare const AuthConfig: z.ZodObject<{
11
12
  trustedOrigins: z.ZodDefault<z.ZodArray<z.ZodString>>;
12
13
  database: z.ZodDefault<z.ZodString>;
13
14
  rateLimiterBinding: z.ZodDefault<z.ZodString>;
14
- google: z.ZodDefault<z.ZodObject<{
15
+ google: z.ZodPrefault<z.ZodObject<{
15
16
  enabled: z.ZodDefault<z.ZodBoolean>;
17
+ allowSignUp: z.ZodDefault<z.ZodBoolean>;
16
18
  }, z.core.$strip>>;
17
- apple: z.ZodDefault<z.ZodObject<{
19
+ apple: z.ZodPrefault<z.ZodObject<{
18
20
  enabled: z.ZodDefault<z.ZodBoolean>;
21
+ allowSignUp: z.ZodDefault<z.ZodBoolean>;
19
22
  }, z.core.$strip>>;
20
- facebook: z.ZodDefault<z.ZodObject<{
23
+ facebook: z.ZodPrefault<z.ZodObject<{
21
24
  enabled: z.ZodDefault<z.ZodBoolean>;
25
+ allowSignUp: z.ZodDefault<z.ZodBoolean>;
22
26
  }, z.core.$strip>>;
23
- github: z.ZodDefault<z.ZodObject<{
27
+ github: z.ZodPrefault<z.ZodObject<{
24
28
  enabled: z.ZodDefault<z.ZodBoolean>;
29
+ allowSignUp: z.ZodDefault<z.ZodBoolean>;
25
30
  }, z.core.$strip>>;
26
31
  sessionExpiresIn: z.ZodDefault<z.ZodNumber>;
27
32
  sessionUpdateAge: z.ZodDefault<z.ZodNumber>;
@@ -39,6 +44,8 @@ export type AuthConfigInput = z.input<typeof AuthConfig>;
39
44
  */
40
45
  export interface AuthWiring {
41
46
  config: AuthConfig;
47
+ /** The adopter's GitHub identity resolver, or `undefined` for the kit's own rule. See {@link AuthOptions}. */
48
+ resolveGithubUserInfo: GithubUserInfoResolver | undefined;
42
49
  /** The email capability's bound enqueue seam — how magic-link/OTP are delivered. Set by `compose`. */
43
50
  enqueueEmail: EmailCapability["enqueue"] | undefined;
44
51
  /** The turnstile login gate, when the turnstile capability is composed. Set by `compose`. */
@@ -46,6 +53,31 @@ export interface AuthWiring {
46
53
  mode: TurnstileMode;
47
54
  } | undefined;
48
55
  }
56
+ /**
57
+ * What `auth()` takes: the config, plus the seams that are **behavior rather than data**.
58
+ *
59
+ * A function cannot live in the Zod schema — the schema is the self-documenting surface `pithy` renders
60
+ * and the config projection serializes, and neither can carry a closure. So the split follows
61
+ * `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
62
+ * destructured off before the parse.
63
+ */
64
+ export type AuthOptions = AuthConfigInput & {
65
+ /**
66
+ * Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
67
+ *
68
+ * The kit's default is deliberately conservative: it links on the **primary** address and nothing else,
69
+ * because GitHub never re-verifies and a verified secondary can only speak to the past. An adopter who
70
+ * wants a richer ladder — match a verified secondary, present a chooser on multiple matches — builds it
71
+ * here. `getUserInfo` is the only hook in this flow running before both fetches and before
72
+ * `mapProfileToUser`, and the only one holding the OAuth token.
73
+ *
74
+ * **Better Auth trusts what you return, verbatim.** It performs no independent check, so an
75
+ * `emailVerified: true` you did not read from GitHub is an account takeover: an attacker adds a
76
+ * victim's address to their own GitHub *unverified* and links to the victim's user. Return GitHub's
77
+ * real per-address flag, always.
78
+ */
79
+ resolveGithubUserInfo?: GithubUserInfoResolver;
80
+ };
49
81
  /** The auth capability, with its resolved config attached for inspection. */
50
82
  export interface AuthCapability extends Capability {
51
83
  authConfig: AuthConfig;
@@ -56,7 +88,7 @@ export interface AuthCapability extends Capability {
56
88
  * `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
57
89
  * and emits `auth/*` through `audit` when those are composed.
58
90
  */
59
- export declare function auth(config: AuthConfigInput): AuthCapability;
91
+ export declare function auth(options: AuthOptions): AuthCapability;
60
92
  /** Type guard: is this capability the auth capability? */
61
93
  export declare function isAuthCapability(capability: Capability): capability is AuthCapability;
62
94
  //# sourceMappingURL=capability.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,0CAA0C,CAAC;AAG5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2BxB,mGAAmG;AACnG,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;iBAsE8B,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,sGAAsG;IACtG,YAAY,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACrD,6FAA6F;IAC7F,SAAS,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,GAAG,SAAS,CAAC;CAChD;AAED,6EAA6E;AAC7E,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,UAAU,EAAE,UAAU,CAAC;CACx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E,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,UAAU,EAAE,UAAU,CAAC;CACxB;AAiCD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA8IzD;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
@@ -21,8 +21,20 @@ import { isTurnstileCapability } from "@pithy-sh/turnstile/src/capability";
21
21
  import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
22
22
  import { z } from "zod";
23
23
  //#region src/capability.ts
24
- /** A social provider toggle. Credentials live in the secrets store, never config. */
25
- const ProviderToggle = z.object({ enabled: z.boolean().default(false).describe("Whether this social provider is enabled. Credentials are read from the secrets store, never config.") }).describe("A social provider's on/off toggle.");
24
+ /**
25
+ * A social provider toggle. Credentials live in the secrets store, never config.
26
+ *
27
+ * **Defaulted with `.prefault({})` rather than `.default({ enabled: false })`, and the difference is not
28
+ * cosmetic.** Zod 4 hands a `.default` value back verbatim without parsing it, so a literal supplied the
29
+ * object's *shape* while silently skipping every inner field default — `allowSignUp` was `undefined` on
30
+ * all four providers until a caller wrote one out by hand, which is precisely the field whose absence
31
+ * must not read as "false". `.prefault` runs the value through the schema, so one place states the
32
+ * defaults and nothing has to restate them.
33
+ */
34
+ const ProviderToggle = z.object({
35
+ enabled: z.boolean().default(false).describe("Whether this social provider is enabled. Credentials are read from the secrets store, never config."),
36
+ allowSignUp: z.boolean().default(true).describe("Whether signing in with this provider may create a new account. When false, a sign-in whose email matches no existing user is refused and nothing is minted — the caller signs in by email first, then connects this provider from their profile. Separate from the top-level `disableSignUp`, which governs magic link and OTP.")
37
+ }).describe("A social provider's on/off toggle and its sign-up policy.");
26
38
  /** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
27
39
  const AuthConfig = z.object({
28
40
  basePath: z.string().default("/auth").describe("The path the auth handler mounts under. Must match the OAuth redirect URIs you register. Defaults to `/auth`."),
@@ -30,10 +42,10 @@ const AuthConfig = z.object({
30
42
  trustedOrigins: z.array(z.string()).default([]).describe("Web origins and mobile deep-link schemes allowed as redirect targets and for cookie CSRF origin checks (e.g. `https://app.example.com`, `myapp://`)."),
31
43
  database: z.string().default("DB").describe("The D1 binding the auth tables and migrations target. Defaults to `DB`, the shared app database."),
32
44
  rateLimiterBinding: z.string().default("AUTH_RATE_LIMITER").describe("The Workers Rate Limiting binding for the coarse per-IP edge guard on the auth routes (tier 1). Its limit and window are set on the binding in wrangler.jsonc. Complements Better Auth's per-action limiter (tier 2)."),
33
- google: ProviderToggle.default({ enabled: false }).describe("Google OAuth. Enable it, then store credentials as the `auth-google-credentials` secret. See docs/google-oauth.md."),
34
- apple: ProviderToggle.default({ enabled: false }).describe("Apple Sign-In. Enable it, then store credentials as the `auth-apple-credentials` secret. See docs/apple-signin.md."),
35
- facebook: ProviderToggle.default({ enabled: false }).describe("Facebook Login. Enable it, then store credentials as the `auth-facebook-credentials` secret. See docs/facebook-oauth.md."),
36
- github: ProviderToggle.default({ enabled: false }).describe("GitHub OAuth. Enable it, then store credentials as the `auth-github-credentials` secret. See docs/github-oauth.md."),
45
+ google: ProviderToggle.prefault({}).describe("Google OAuth. Enable it, then store credentials as the `auth-google-credentials` secret. See docs/google-oauth.md."),
46
+ apple: ProviderToggle.prefault({}).describe("Apple Sign-In. Enable it, then store credentials as the `auth-apple-credentials` secret. See docs/apple-signin.md."),
47
+ facebook: ProviderToggle.prefault({}).describe("Facebook Login. Enable it, then store credentials as the `auth-facebook-credentials` secret. See docs/facebook-oauth.md."),
48
+ github: ProviderToggle.prefault({}).describe("GitHub OAuth. Enable it, then store credentials as the `auth-github-credentials` secret. See docs/github-oauth.md."),
37
49
  sessionExpiresIn: z.number().int().default(604800).describe("Session (refresh credential) lifetime in seconds. Defaults to 7 days. Expiry slides forward on use."),
38
50
  sessionUpdateAge: z.number().int().default(86400).describe("How often (seconds) an active session's expiry slides forward. Defaults to 1 day."),
39
51
  verificationExpiresIn: z.number().int().default(300).describe("Magic-link and OTP lifetime in seconds. Defaults to 5 minutes. Single-use regardless."),
@@ -71,12 +83,14 @@ function assertPluginTablesUnclaimed(capabilities, binding, extensions) {
71
83
  * `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
72
84
  * and emits `auth/*` through `audit` when those are composed.
73
85
  */
74
- function auth(config) {
86
+ function auth(options) {
87
+ const { resolveGithubUserInfo, ...config } = options;
75
88
  const resolved = AuthConfig.parse(config);
76
89
  assertAdditivePlugins(resolved.plugins);
77
90
  const pluginPlan = authPluginPlan(resolved.plugins);
78
91
  const wiring = {
79
92
  config: resolved,
93
+ resolveGithubUserInfo,
80
94
  enqueueEmail: void 0,
81
95
  turnstile: void 0
82
96
  };
@@ -293,9 +293,17 @@ export type SocialSignIn = {
293
293
  * **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
294
294
  * own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
295
295
  * magic-link route alone. Gating it would only stop people signing in.
296
+ *
297
+ * **`errorCallbackURL` is how a refusal gets back to a screen at all.** Absent it, Better Auth sends a
298
+ * refused callback to `${baseURL}${basePath}/error`, which in production redirects on to the adopter's
299
+ * home route carrying a query string no template reads — so the user lands on a page that says nothing
300
+ * about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
301
+ * that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
302
+ * (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
296
303
  */
297
304
  export declare function startSocialSignIn(input: {
298
305
  provider: string;
299
306
  callbackURL: string;
307
+ errorCallbackURL?: string;
300
308
  }, options?: AuthClientOptions): Promise<SocialSignIn>;
301
309
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACrC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,EACzC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAC7C,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AA0B9C;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3E,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAOvB"}
@@ -367,6 +367,13 @@ function isAuthorization(value) {
367
367
  * **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
368
368
  * own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
369
369
  * magic-link route alone. Gating it would only stop people signing in.
370
+ *
371
+ * **`errorCallbackURL` is how a refusal gets back to a screen at all.** Absent it, Better Auth sends a
372
+ * refused callback to `${baseURL}${basePath}/error`, which in production redirects on to the adopter's
373
+ * home route carrying a query string no template reads — so the user lands on a page that says nothing
374
+ * about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
375
+ * that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
376
+ * (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
370
377
  */
371
378
  async function startSocialSignIn(input, options) {
372
379
  const ungated = options && {
@@ -86,6 +86,13 @@ async function buildAuthInstance(c, wiring) {
86
86
  verificationExpiresIn: cfg.verificationExpiresIn,
87
87
  otpLength: cfg.otpLength,
88
88
  disableSignUp: cfg.disableSignUp,
89
+ providerSignUp: {
90
+ google: cfg.google.allowSignUp,
91
+ apple: cfg.apple.allowSignUp,
92
+ facebook: cfg.facebook.allowSignUp,
93
+ github: cfg.github.allowSignUp
94
+ },
95
+ ...wiring.resolveGithubUserInfo ? { resolveGithubUserInfo: wiring.resolveGithubUserInfo } : {},
89
96
  emit: (event) => c.var.emit(event),
90
97
  plugins: cfg.plugins
91
98
  });
@@ -3,17 +3,8 @@
3
3
  import type { AuditEmit } from "@pithy-sh/core/src/audit/recorder";
4
4
  import { type BetterAuthPlugin } from "better-auth";
5
5
  import type { AuthDatabase } from "../data/tables";
6
- import { type ResolvedProviders } from "./providers";
7
- /**
8
- * Build the `socialProviders` block from whichever provider credentials were resolved. Exported so the
9
- * per-provider branch matrix is unit-testable without constructing a Better Auth instance — it reads
10
- * only the resolved credentials on `deps`, never the database.
11
- *
12
- * **Only a `ready` provider is registered.** A `disabled` one never was; an `unresolvable` one is the
13
- * change #381 made, and it is what keeps magic link and OTP working while one credential is unreadable.
14
- * The narrowing is the type's doing rather than this function's discipline — `deps.google.credentials`
15
- * does not exist until `state === "ready"` has been established.
16
- */
6
+ import { type GithubUserInfoResolver } from "./githubUserInfo";
7
+ import { type ResolvedProviders, type SocialProviderId } from "./providers";
17
8
  export declare function socialProviders(deps: AuthInstanceDeps): Record<string, unknown> | undefined;
18
9
  /**
19
10
  * The seeding guard: a new account may be created only for an email a provider has **verified**.
@@ -78,8 +69,26 @@ export interface AuthInstanceDeps<Plugins extends readonly BetterAuthPlugin[] =
78
69
  verificationExpiresIn: number;
79
70
  /** OTP length (digits). */
80
71
  otpLength: number;
81
- /** When true, sign-in never provisions a new user (existing accounts only). */
72
+ /** When true, sign-in never provisions a new user (existing accounts only). Magic link and OTP. */
82
73
  disableSignUp: boolean;
74
+ /**
75
+ * Whether each social provider may create an account, from that provider's `allowSignUp` toggle.
76
+ *
77
+ * **A second question from {@link disableSignUp}, and the reason it is separate.** The dashboard needs
78
+ * *email* sign-up — somebody creating an organization — and *no* GitHub sign-up. One global boolean
79
+ * cannot say that, and the gap is exactly how a GitHub sign-in minted a second, empty user beside the
80
+ * real account (pithy-sh/pithy#554). Better Auth has supported this per provider all along; the kit
81
+ * simply never surfaced it.
82
+ */
83
+ providerSignUp: Readonly<Record<SocialProviderId, boolean>>;
84
+ /**
85
+ * How a GitHub identity is resolved, or `undefined` for the kit's own rule.
86
+ *
87
+ * The one seam an adopter overrides to build a richer ladder — `getUserInfo` is the only hook running
88
+ * before both fetches and before `mapProfileToUser`, and the only one holding the OAuth token. See
89
+ * `githubUserInfo.ts` for the default and why it is primary-only.
90
+ */
91
+ resolveGithubUserInfo?: GithubUserInfoResolver;
83
92
  /** Audit seam — emits `auth/*` events. A no-op when the audit capability is absent. */
84
93
  emit: AuditEmit;
85
94
  /**
@@ -230,6 +239,22 @@ export declare function makeAuth<const Plugins extends readonly BetterAuthPlugin
230
239
  accountLinking: {
231
240
  enabled: true;
232
241
  trustedProviders: ("apple" | "google")[];
242
+ /**
243
+ * **A provider is never the last way in, which is also what makes an orphaned link recoverable.**
244
+ *
245
+ * Better Auth refuses to unlink somebody's only account, on the reasonable fear of locking them
246
+ * out. That fear does not apply here: magic link is unconditional in this kit, so every user can
247
+ * always reach their own address, and the "last account" it is protecting is a provider link
248
+ * rather than a credential.
249
+ *
250
+ * It also settles #554's orphan without a merge rule. A GitHub sign-in that minted an empty user
251
+ * holds the provider identity, so linking it to the real account collides. With this, the owner
252
+ * of that empty account — who controls its address, or magic link could not have created it —
253
+ * signs in, unlinks GitHub, and links it where it belongs. At no point does one account take an
254
+ * identity from another; one gives it up, authenticated as itself. A claim-from-an-empty-account
255
+ * rule is where takeover bugs live, and this needs none.
256
+ */
257
+ allowUnlinkingAll: true;
233
258
  };
234
259
  };
235
260
  verification: {
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/instance/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,aAAa,CAAC;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAuB,KAAK,iBAAiB,EAA0B,MAAM,aAAa,CAAC;AAElG;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA4C3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IAAE,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,GAAG,OAAO,CAEpF;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,M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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUtD"}
@@ -3,6 +3,7 @@
3
3
  import { emitAfterRequest, emitProviderUnavailable } from "../audit/emit.js";
4
4
  import { KIT_SESSION_FIELDS, KIT_USER_FIELDS } from "../data/kitFields.js";
5
5
  import { parseDeviceMeta, registerDevice } from "../device/registry.js";
6
+ import { defaultGithubUserInfo } from "./githubUserInfo.js";
6
7
  import { kitPlugins } from "./plugins.js";
7
8
  import { providerUnavailable, unavailableProviderFor } from "./providers.js";
8
9
  import { betterAuth } from "better-auth";
@@ -18,32 +19,53 @@ import { APIError, createAuthMiddleware } from "better-auth/api";
18
19
  * The narrowing is the type's doing rather than this function's discipline — `deps.google.credentials`
19
20
  * does not exist until `state === "ready"` has been established.
20
21
  */
22
+ /**
23
+ * One provider's sign-up policy, in Better Auth's spelling.
24
+ *
25
+ * **Applied by every provider block, because the toggle is declared on every provider.** `allowSignUp`
26
+ * lives on the shared `ProviderToggle`, so an adopter can write it for google, apple or facebook exactly
27
+ * as readily as for github — and a policy the config accepts, describes and type-checks while the
28
+ * instance ignores it is worse than one that was never offered. It shipped github-only for one round;
29
+ * the reason nobody noticed is that github is the provider anybody testing this would try.
30
+ *
31
+ * Permitted is the **absence** of the key rather than `disableSignUp: false`, so the default path asserts
32
+ * nothing and Better Auth's own default stands. It reads this off `provider.options` at
33
+ * `callback.mjs:229`.
34
+ */
35
+ function signUpOption(allowed) {
36
+ return allowed ? {} : { disableSignUp: true };
37
+ }
21
38
  function socialProviders(deps) {
22
39
  const providers = {};
23
40
  if (deps.google.state === "ready") providers.google = {
24
41
  clientId: deps.google.credentials.clientId,
25
42
  clientSecret: deps.google.credentials.clientSecret,
26
43
  accessType: "offline",
27
- prompt: "select_account consent"
44
+ prompt: "select_account consent",
45
+ ...signUpOption(deps.providerSignUp.google)
28
46
  };
29
47
  if (deps.apple.state === "ready") {
30
48
  const apple = deps.apple.credentials;
31
49
  providers.apple = {
32
50
  clientId: apple.clientId,
33
51
  clientSecret: apple.clientSecret,
34
- ...apple.appBundleIdentifier ? { appBundleIdentifier: apple.appBundleIdentifier } : {}
52
+ ...apple.appBundleIdentifier ? { appBundleIdentifier: apple.appBundleIdentifier } : {},
53
+ ...signUpOption(deps.providerSignUp.apple)
35
54
  };
36
55
  }
37
56
  if (deps.facebook.state === "ready") providers.facebook = {
38
57
  clientId: deps.facebook.credentials.clientId,
39
58
  clientSecret: deps.facebook.credentials.clientSecret,
40
59
  scope: ["email"],
41
- mapProfileToUser: () => ({ emailVerified: true })
60
+ mapProfileToUser: () => ({ emailVerified: true }),
61
+ ...signUpOption(deps.providerSignUp.facebook)
42
62
  };
43
63
  if (deps.github.state === "ready") providers.github = {
44
64
  clientId: deps.github.credentials.clientId,
45
65
  clientSecret: deps.github.credentials.clientSecret,
46
- scope: ["user:email"]
66
+ scope: ["user:email"],
67
+ getUserInfo: deps.resolveGithubUserInfo ?? defaultGithubUserInfo(),
68
+ ...signUpOption(deps.providerSignUp.github)
47
69
  };
48
70
  return Object.keys(providers).length > 0 ? providers : void 0;
49
71
  }
@@ -163,7 +185,23 @@ function makeAuth(deps) {
163
185
  modelName: "pithyAuthAccounts",
164
186
  accountLinking: {
165
187
  enabled: true,
166
- trustedProviders: ["google", "apple"]
188
+ trustedProviders: ["google", "apple"],
189
+ /**
190
+ * **A provider is never the last way in, which is also what makes an orphaned link recoverable.**
191
+ *
192
+ * Better Auth refuses to unlink somebody's only account, on the reasonable fear of locking them
193
+ * out. That fear does not apply here: magic link is unconditional in this kit, so every user can
194
+ * always reach their own address, and the "last account" it is protecting is a provider link
195
+ * rather than a credential.
196
+ *
197
+ * It also settles #554's orphan without a merge rule. A GitHub sign-in that minted an empty user
198
+ * holds the provider identity, so linking it to the real account collides. With this, the owner
199
+ * of that empty account — who controls its address, or magic link could not have created it —
200
+ * signs in, unlinks GitHub, and links it where it belongs. At no point does one account take an
201
+ * identity from another; one gives it up, authenticated as itself. A claim-from-an-empty-account
202
+ * rule is where takeover bugs live, and this needs none.
203
+ */
204
+ allowUnlinkingAll: true
167
205
  }
168
206
  },
169
207
  verification: { modelName: "pithyAuthVerifications" },
@@ -0,0 +1,129 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { z } from "zod";
4
+ /**
5
+ * How `@pithy-sh/auth` resolves a GitHub identity — **primary match links, and nothing else does.**
6
+ *
7
+ * **The defect this replaces.** Better Auth's stock GitHub provider keeps the primary address from
8
+ * `/user/emails`, and falls back to `emails[0]` when the profile carried no email at all. Nothing matches
9
+ * an existing user by any other address. So a GitHub account whose primary is not the address somebody
10
+ * signed up with cannot reach their account — and, worse, signing in mints a *second, empty* user under
11
+ * the personal address while the real one sits untouched (pithy-sh/pithy#554). That is the common setup,
12
+ * not an edge case: a personal primary with the work address secondary is how most people's GitHub is.
13
+ *
14
+ * **And matching a verified secondary is still the wrong fix.** It looks defensible — GitHub only marks
15
+ * an address verified after delivering a confirmation to it, so a verified secondary does prove real
16
+ * mailbox control. *At some point.* GitHub never re-verifies. A work address from a job somebody left
17
+ * three years ago stays verified on their personal account forever, and addresses get reassigned.
18
+ * Linking is a decision about **present** control, and a stale verified secondary can only speak to the
19
+ * past. The cost of refusing is one extra sign-in, once: after connecting from the profile, sign-in
20
+ * resolves by account id and the primary stops mattering permanently.
21
+ *
22
+ * So this module is deliberately smaller than the prior art it is lifted from. It differs from the stock
23
+ * provider in exactly three ways, and each is load-bearing:
24
+ *
25
+ * 1. **It fails closed.** A fetch that does not answer resolves `null`, which is distinguishable from an
26
+ * account with no verified address. Collapsing the two renders a GitHub outage as "your account does
27
+ * not exist", which sends somebody to fix an account that is fine.
28
+ * 2. **It branches on the OAuth state.** See {@link defaultGithubUserInfo} — this is the whole of phase 1.
29
+ * 3. **It never falls back to a non-primary address**, and it never asserts a verified flag it did not
30
+ * read from GitHub.
31
+ *
32
+ * **Linking is Better Auth's branch, not this one, and that is worth knowing before editing here.**
33
+ * `getUserInfo` runs at `callback.mjs:120`, upstream of the `if (link)` at `:150`, and it is handed only
34
+ * the tokens — 1.7.1 exports no accessor that would let it read the OAuth state, so it genuinely cannot
35
+ * tell a `/link-social` callback from a sign-in. It does not need to: what this module contributes to
36
+ * that path is the boundary. The only address it ever returns is one GitHub reports `verified` for, so a
37
+ * link licensed by an address GitHub never confirmed is not reachable from either flow. Linking also
38
+ * cannot rewrite the user's own email — `applyUpdateUserInfoOnLink` returns early unless
39
+ * `updateUserInfoOnLink` is set, and destructures `email` out even then.
40
+ *
41
+ * **Linking a provider whose address *differs* from the account's is not enabled here, and that is a
42
+ * deliberate hold.** It needs `allowDifferentEmails: true`, which widens what a session alone can do —
43
+ * and the control that pays for it has to survive `/token/rotate`, which mints a session stamped
44
+ * `createdAt: now`. A gate on session age is therefore reset by an ordinary rotation and by any attacker
45
+ * holding a stolen refresh token, so it needs an `authenticatedAt` that rotation carries forward. That is
46
+ * a session-schema change and ships on its own.
47
+ *
48
+ * An earlier draft carried a `link` branch here that preferred the session's own address. It was dead:
49
+ * nothing could supply the session email, so the branch never ran. It is gone rather than left as a seam
50
+ * nobody can reach.
51
+ */
52
+ /** One entry of GitHub's `/user/emails` page. The `verified` flag is the only thing that may license a link. */
53
+ export declare const GithubEmail: z.ZodObject<{
54
+ email: z.ZodString;
55
+ primary: z.ZodBoolean;
56
+ verified: z.ZodBoolean;
57
+ }, z.core.$strip>;
58
+ export type GithubEmail = z.infer<typeof GithubEmail>;
59
+ /** The slice of GitHub's `/user` profile the kit depends on. Everything else travels through untouched. */
60
+ export declare const GithubProfile: z.ZodObject<{
61
+ id: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
62
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
63
+ login: z.ZodOptional<z.ZodNullable<z.ZodString>>;
64
+ avatar_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
65
+ }, z.core.$loose>;
66
+ export type GithubProfile = z.infer<typeof GithubProfile>;
67
+ /** A GitHub identity: the profile, and every address the token can see. */
68
+ export interface GithubIdentity {
69
+ /** The `/user` profile, untouched — this is what travels back as `data`. */
70
+ profile: GithubProfile;
71
+ /** The `/user/emails` page. Never returned to a caller; see {@link defaultGithubUserInfo}. */
72
+ emails: readonly GithubEmail[];
73
+ }
74
+ /**
75
+ * Parse one `/user` + `/user/emails` pair, or `null` when either is not what GitHub promises.
76
+ *
77
+ * **`null` rather than a partial identity, and that is the fail-closed half.** A profile with no `id` and
78
+ * an email payload that is not a list are both GitHub failing to answer, not a user with an unusual
79
+ * account — and the difference decides whether the operator reads "GitHub is down" or the user reads
80
+ * "your account does not exist".
81
+ */
82
+ export declare function githubIdentityFrom(profile: unknown, emails: unknown): GithubIdentity | null;
83
+ /** The address a sign-in resolves to, with GitHub's own flag — or `null` when the account has no primary. */
84
+ export interface ResolvedGithubEmail {
85
+ email: string;
86
+ emailVerified: boolean;
87
+ }
88
+ /**
89
+ * The settled rule, as one function: **the primary entry, and its real `verified` flag.**
90
+ *
91
+ * `null` when there is no primary at all. Deliberately not `emails[0]`: that fallback is the second way
92
+ * the stock provider silently picks a non-primary address, and a rule with an exception in it is not the
93
+ * rule this issue settled.
94
+ */
95
+ export declare function resolveGithubEmail(emails: readonly GithubEmail[]): ResolvedGithubEmail | null;
96
+ /** Fetch one JSON document with a bearer token, or `null` on any failure. Injected so tests never call out. */
97
+ export type FetchJson = (url: string, accessToken: string) => Promise<unknown>;
98
+ /** What {@link defaultGithubUserInfo} needs from the world. Both injected, so the resolver is a pure unit. */
99
+ export interface GithubUserInfoDeps {
100
+ /** Read a GitHub API document. Defaults to the real `fetch`. */
101
+ fetchJson?: FetchJson;
102
+ }
103
+ /** What Better Auth expects back: the user fields it will write, and the raw profile it keys the account on. */
104
+ export interface GithubUserInfoResult {
105
+ user: {
106
+ email?: string;
107
+ emailVerified: boolean;
108
+ name: string;
109
+ image?: string;
110
+ } & Record<string, unknown>;
111
+ data: GithubProfile;
112
+ }
113
+ /**
114
+ * A GitHub identity resolver, in the shape Better Auth's `provider.getUserInfo` expects.
115
+ *
116
+ * **An adopter may replace this**, which is the extension point #554 asks for: `getUserInfo` is the only
117
+ * hook in this flow that runs before both fetches and before `mapProfileToUser`, and the only one holding
118
+ * the OAuth token. Somebody wanting a richer ladder — match a verified secondary, present a chooser on
119
+ * multiple matches — builds it here rather than forking the provider block.
120
+ *
121
+ * **The address list never travels in `data`.** `/account-info` serializes the return value to the
122
+ * client, so every address on somebody's GitHub would be readable by the page. Only the profile goes back.
123
+ */
124
+ export type GithubUserInfoResolver = (token: {
125
+ accessToken?: string;
126
+ }) => Promise<GithubUserInfoResult | null>;
127
+ /** The kit's resolver. See {@link GithubUserInfoResolver} and this module's own docblock for the rule. */
128
+ export declare function defaultGithubUserInfo(deps?: GithubUserInfoDeps): GithubUserInfoResolver;
129
+ //# sourceMappingURL=githubUserInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"githubUserInfo.d.ts","sourceRoot":"","sources":["../../src/instance/githubUserInfo.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,gHAAgH;AAChH,eAAO,MAAM,WAAW;;;;iBAYiF,CAAC;AAC1G,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,2GAA2G;AAC3G,eAAO,MAAM,aAAa;;;;;iBAkBkF,CAAC;AAC7G,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,2EAA2E;AAC3E,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,OAAO,EAAE,aAAa,CAAC;IACvB,8FAA8F;IAC9F,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;CAChC;AAED;;;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