1 Commits

Author SHA1 Message Date
Sahaj Jain bb8df47a8c OAuth 2.0 API for external app integrations (#267)
* OAuth 2.0 API for external app integrations

Implements the Authorization Code flow so external apps can
authenticate tweakcn users and access their themes/profile
via a REST API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: simplify OAuth API routes and improve efficiency

- Extract `requireAuth` helper to eliminate duplicated auth+scope
  boilerplate across all v1 API routes
- Narrow SELECT queries to only fetch needed columns in hot paths
  (resolveUserFromBearerToken, authenticateClient, authorize, token)
- Reuse `generateSecureToken`/`hashSecret` in create-oauth-app script
  instead of duplicating crypto logic
- Unify sign-in handlers and loading state in OAuth authorize page
- Use `oauthError` consistently for 404 responses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* replace demo app with OAuth API documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add /api/oauth/userinfo endpoint for genericOAuth compatibility

Returns flat OIDC-style fields (sub, name, email, picture) so
Better Auth's genericOAuth plugin and similar clients work
out of the box without custom getUserInfo mapping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 22:05:20 +05:30