You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/api/docs/replace-oauth-server-with-better-auth.md
+29-6Lines changed: 29 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,21 @@
3
3
**Objective**
4
4
Replace SendLit’s custom OAuth2/auth implementation with Better Auth to support secure first-party web login, MCP OAuth, REST API authentication, and social login with Google plus Email OTP.
5
5
6
+
**Implementation status**
7
+
8
+
Better Auth remains SendLit's product-local authorization server and owns its
9
+
users, sessions, OAuth clients, consent, signing keys, and database adapter.
10
+
The shared `@codelitdev/oauth-server-kit` now owns the reusable protocol layer:
11
+
safe OAuth-provider defaults, hosted login/consent pages, session and bearer
12
+
authentication results, and MCP/OAuth discovery metadata. SendLit continues to
13
+
own organization keys, team keys, organization provisioning, team membership,
14
+
multi-team OAuth selection, and authorization after authentication.
15
+
16
+
MCP Dynamic Client Registration (DCR) is intentionally enabled. Clients may
17
+
register public OAuth clients without prior credentials, but registration is
18
+
limited to SendLit's declared OAuth scopes; public clients must use PKCE.
19
+
Unauthenticated registration is rate-limited to 20 requests per IP per minute.
20
+
6
21
**Background**
7
22
SendLit currently has a custom OAuth2 implementation in `apps/api/src/oauth/*` and a BFF session/token flow in `apps/web/app/api/auth/*` and `apps/web/app/api/proxy/[...path]/route.ts`.
8
23
@@ -248,14 +263,20 @@ type AuthResult =
248
263
249
264
Resolution order:
250
265
251
-
1. API key if `x-sendlit-apikey` is present.
252
-
2. OAuth bearer token if `Authorization: Bearer` is present.
253
-
3. Better Auth session if cookies are present.
254
-
4. Missing/unauthorized.
266
+
1. An explicit organization key when `Authorization: Bearer sl_org_live_...`
267
+
is present.
268
+
2. An OAuth bearer token for every other explicit `Authorization: Bearer`
269
+
credential.
270
+
3. A team API key from `x-sendlit-apikey` or the legacy request body field.
271
+
4. A Better Auth session if cookies are present.
272
+
5. Missing/unauthorized.
255
273
256
274
Important:
257
275
258
276
- Invalid bearer token must not fall back to API key.
277
+
- An organization key is SendLit product authentication, not an OAuth token;
278
+
it is accepted only for its explicit `sl_org_live_...` prefix and is then
279
+
authorized by its own SendLit scopes.
259
280
- API key must remain team-scoped.
260
281
- Session/OAuth account auth must still pass through team membership checks.
261
282
@@ -266,8 +287,10 @@ Important:
266
287
- Dashboard must not store bearer tokens in localStorage.
267
288
- OAuth public clients must use PKCE.
268
289
- Dynamic client registration must be intentionally configured:
0 commit comments