@startino/better-auth-oidc 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Startino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # @startino/better-auth-oidc
2
+
3
+ OIDC-only SSO plugin for [Better Auth](https://www.better-auth.com/). Runs on any JavaScript runtime without Node.js-specific APIs.
4
+
5
+ ## Why
6
+
7
+ The official [`@better-auth/sso`](https://www.better-auth.com/docs/plugins/sso) plugin imports `samlify` at module load, which requires Node.js-only APIs (`node:crypto`, `node:buffer`). This breaks in edge runtimes, serverless environments, or any platform without full Node.js compatibility, even if you only need OIDC.
8
+
9
+ This package extracts the OIDC code paths into a standalone package. SAML code and Node.js dependencies are removed entirely.
10
+
11
+ ## Runtime compatibility
12
+
13
+ | Runtime | `@better-auth/sso` | `@startino/better-auth-oidc` |
14
+ |---|---|---|
15
+ | Node.js | Yes | Yes |
16
+ | Convex | No | Yes |
17
+ | Cloudflare Workers | No | Yes |
18
+ | Deno | No | Yes |
19
+ | Bun | Yes | Yes |
20
+ | Vercel Edge | No | Yes |
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ # bun
26
+ bun add @startino/better-auth-oidc
27
+
28
+ # npm
29
+ npm install @startino/better-auth-oidc
30
+
31
+ # pnpm
32
+ pnpm add @startino/better-auth-oidc
33
+ ```
34
+
35
+ Peer dependencies: `better-auth` (>=1.4.0) and `better-call` (>=1.0.0).
36
+
37
+ ## Quick start
38
+
39
+ ### Server
40
+
41
+ ```ts
42
+ import { betterAuth } from "better-auth";
43
+ import { oidcSso } from "@startino/better-auth-oidc";
44
+
45
+ export const auth = betterAuth({
46
+ // ... your config
47
+ plugins: [
48
+ oidcSso({
49
+ // Optional: provision users into orgs on first sign-in
50
+ organizationProvisioning: {
51
+ defaultRole: "member",
52
+ },
53
+ // Optional: verify domain ownership via DNS TXT records
54
+ domainVerification: {
55
+ enabled: true,
56
+ },
57
+ }),
58
+ ],
59
+ });
60
+ ```
61
+
62
+ ### Client
63
+
64
+ ```ts
65
+ import { createAuthClient } from "better-auth/client";
66
+ import { oidcSsoClient } from "@startino/better-auth-oidc/client";
67
+
68
+ const client = createAuthClient({
69
+ plugins: [
70
+ oidcSsoClient({
71
+ // Must match server config
72
+ domainVerification: { enabled: true },
73
+ }),
74
+ ],
75
+ });
76
+
77
+ // Register an OIDC provider
78
+ await client.sso.register({
79
+ providerId: "okta-acme",
80
+ issuer: "https://acme.okta.com",
81
+ domain: "acme.com",
82
+ oidcConfig: {
83
+ clientId: "your-client-id",
84
+ clientSecret: "your-client-secret",
85
+ },
86
+ });
87
+
88
+ // Sign in with SSO
89
+ await client.signIn.sso({
90
+ email: "user@acme.com",
91
+ callbackURL: "/dashboard",
92
+ });
93
+ ```
94
+
95
+ ## Configuration options
96
+
97
+ | Option | Type | Default | Description |
98
+ |---|---|---|---|
99
+ | `provisionUser` | `function` | - | Custom function called when a new user signs in via SSO |
100
+ | `organizationProvisioning` | `object` | - | Auto-assign users to orgs based on SSO provider |
101
+ | `organizationProvisioning.defaultRole` | `"member" \| "admin"` | `"member"` | Default role for auto-provisioned members |
102
+ | `organizationProvisioning.getRole` | `function` | - | Dynamic role assignment function |
103
+ | `defaultSSO` | `array` | - | Default provider configs for testing (takes precedence over DB) |
104
+ | `defaultOverrideUserInfo` | `boolean` | `false` | Override user info with provider data on each sign-in |
105
+ | `disableImplicitSignUp` | `boolean` | `false` | Require explicit `requestSignUp: true` to create new users |
106
+ | `modelName` | `string` | `"ssoProvider"` | Custom table name for SSO providers |
107
+ | `fields` | `object` | - | Custom field name mappings for the provider table |
108
+ | `providersLimit` | `number \| function` | `10` | Max providers per user (0 to disable registration) |
109
+ | `trustEmailVerified` | `boolean` | `false` | Trust the `email_verified` claim from the IdP (deprecated) |
110
+ | `domainVerification` | `object` | - | Enable DNS-based domain ownership verification |
111
+ | `domainVerification.enabled` | `boolean` | `false` | Enable/disable the feature |
112
+ | `domainVerification.tokenPrefix` | `string` | `"better-auth-token"` | Prefix for the DNS TXT record identifier |
113
+
114
+ ## Endpoints
115
+
116
+ | Endpoint | Method | Description |
117
+ |---|---|---|
118
+ | `/sso/register` | POST | Register a new OIDC provider |
119
+ | `/sign-in/sso` | POST | Initiate SSO sign-in (redirects to IdP) |
120
+ | `/sso/callback/:providerId` | GET | OAuth2 callback handler |
121
+ | `/sso/providers` | GET | List providers the user has access to |
122
+ | `/sso/get-provider` | GET | Get details for a specific provider |
123
+ | `/sso/update-provider` | POST | Update an existing provider |
124
+ | `/sso/delete-provider` | POST | Delete a provider |
125
+ | `/sso/request-domain-verification` | POST | Request domain verification (if enabled) |
126
+ | `/sso/verify-domain` | POST | Verify domain via DNS TXT record (if enabled) |
127
+
128
+ ## Domain verification
129
+
130
+ When `domainVerification.enabled` is `true`, new providers require DNS-based domain ownership verification before sign-ins are allowed.
131
+
132
+ 1. Register a provider. The response includes a `domainVerificationToken`.
133
+ 2. Create a DNS TXT record: `_better-auth-token-<providerId>.<domain>` with value `_better-auth-token-<providerId>=<token>`.
134
+ 3. Call the verify endpoint. The plugin resolves the TXT record via DNS-over-HTTPS (Cloudflare) and confirms ownership.
135
+
136
+ No `node:dns` required. Verification works on any runtime with `fetch`.
137
+
138
+ ## Migration from `@better-auth/sso`
139
+
140
+ | `@better-auth/sso` | `@startino/better-auth-oidc` |
141
+ |---|---|
142
+ | `import { sso } from "@better-auth/sso"` | `import { oidcSso } from "@startino/better-auth-oidc"` |
143
+ | `import { ssoClient } from "@better-auth/sso/client"` | `import { oidcSsoClient } from "@startino/better-auth-oidc/client"` |
144
+ | `sso({ ... })` | `oidcSso({ ... })` |
145
+ | `ssoClient({ ... })` | `oidcSsoClient({ ... })` |
146
+ | Plugin ID: `"sso"` | Plugin ID: `"oidc-sso"` |
147
+ | `samlConfig` in options/schema | Removed (OIDC only) |
148
+ | `saml` options block | Removed |
149
+ | `defaultSSO[].samlConfig` | Removed |
150
+ | `fields.samlConfig` | Removed |
151
+
152
+ The database schema is the same minus the `samlConfig` column. If migrating from `@better-auth/sso`, you can drop the `samlConfig` column from your `ssoProvider` table, or leave it (it will be ignored).
153
+
154
+ ## Credits
155
+
156
+ This package is an OIDC-only extraction of [`@better-auth/sso`](https://github.com/better-auth/better-auth/tree/main/packages/sso) by [Bereket Engida](https://github.com/bereketa). All OIDC logic, discovery pipeline, organization linking, and provider management code originates from that package.
157
+
158
+ ## License
159
+
160
+ MIT
@@ -0,0 +1,25 @@
1
+ import { OIDCSSOPlugin } from "./index.js";
2
+
3
+ //#region src/client.d.ts
4
+ interface OIDCSSOClientOptions {
5
+ domainVerification?: {
6
+ enabled: boolean;
7
+ } | undefined;
8
+ }
9
+ declare const oidcSsoClient: <CO extends OIDCSSOClientOptions>(options?: CO | undefined) => {
10
+ id: "oidc-sso-client";
11
+ $InferServerPlugin: OIDCSSOPlugin<{
12
+ domainVerification: {
13
+ enabled: CO["domainVerification"] extends {
14
+ enabled: true;
15
+ } ? true : false;
16
+ };
17
+ }>;
18
+ pathMethods: {
19
+ "/sso/providers": "GET";
20
+ "/sso/get-provider": "GET";
21
+ };
22
+ };
23
+ //#endregion
24
+ export { oidcSsoClient };
25
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"sourcesContent":[],"mappings":";;;UAGU,oBAAA;;IAAA,OAAA,EAAA,OAAA;EAQG,CAAA,GAAA,SAAA;;AAA4B,cAA5B,aAA4B,EAAA,CAAA,WAAA,oBAAA,CAAA,CAAA,OAAA,CAAA,EAC9B,EAD8B,GAAA,SAAA,EAAA,GAAA;MAC9B,iBAAA;oBAME,EAFe,aAEf,CAAA;IAFe,kBAAA,EAAA;MAAa,OAAA,EAE5B,EAF4B,CAAA,oBAAA,CAAA,SAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,15 @@
1
+ //#region src/client.ts
2
+ const oidcSsoClient = (options) => {
3
+ return {
4
+ id: "oidc-sso-client",
5
+ $InferServerPlugin: {},
6
+ pathMethods: {
7
+ "/sso/providers": "GET",
8
+ "/sso/get-provider": "GET"
9
+ }
10
+ };
11
+ };
12
+
13
+ //#endregion
14
+ export { oidcSsoClient };
15
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport type { OIDCSSOPlugin } from \"./index\";\n\ninterface OIDCSSOClientOptions {\n\tdomainVerification?:\n\t\t| {\n\t\t\t\tenabled: boolean;\n\t\t }\n\t\t| undefined;\n}\n\nexport const oidcSsoClient = <CO extends OIDCSSOClientOptions>(\n\toptions?: CO | undefined,\n) => {\n\treturn {\n\t\tid: \"oidc-sso-client\",\n\t\t$InferServerPlugin: {} as OIDCSSOPlugin<{\n\t\t\tdomainVerification: {\n\t\t\t\tenabled: CO[\"domainVerification\"] extends { enabled: true }\n\t\t\t\t\t? true\n\t\t\t\t\t: false;\n\t\t\t};\n\t\t}>,\n\t\tpathMethods: {\n\t\t\t\"/sso/providers\": \"GET\",\n\t\t\t\"/sso/get-provider\": \"GET\",\n\t\t},\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";AAWA,MAAa,iBACZ,YACI;AACJ,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EAOtB,aAAa;GACZ,kBAAkB;GAClB,qBAAqB;GACrB;EACD"}