Backend Setup
Prerequisites
Section titled “Prerequisites”- Bun runtime (v1.0+)
- SQLite database
- OAuth client credentials from providers (optional for testing)
Installation
Section titled “Installation”Clone the repository and install dependencies:
git clone <repository-url>cd proof-of-spendbun installDatabase Setup
Section titled “Database Setup”Initialize the SQLite database with Drizzle ORM:
# Generate migrationsbun run drizzle-kit generate
# Run migrationsbun run drizzle-kit migrateEnvironment Configuration
Section titled “Environment Configuration”Create a .env file in the project root:
# Server ConfigurationPORT=3000NODE_ENV=development
# DatabaseDATABASE_URL=./data/proof-of-spend.db
# JWT SecretsJWT_ACCESS_SECRET=your-secret-key-hereJWT_REFRESH_SECRET=your-refresh-secret-here
# OAuth Provider Credentials (optional for testing)OPENAI_CLIENT_ID=your-openai-client-idOPENAI_CLIENT_SECRET=your-openai-client-secret
ANTHROPIC_CLIENT_ID=your-anthropic-client-idANTHROPIC_CLIENT_SECRET=your-anthropic-client-secret
GOOGLE_CLIENT_ID=your-google-client-idGOOGLE_CLIENT_SECRET=your-google-client-secretRegister OAuth Clients
Section titled “Register OAuth Clients”Register your application as an OAuth client:
curl -X POST http://localhost:3000/oauth/register \ -H "Content-Type: application/json" \ -d '{ "name": "My Annotation App", "redirectUris": ["http://localhost:3001/callback"], "grantTypes": ["authorization_code", "refresh_token"] }'Save the client_id and client_secret from the response.
Start the Server
Section titled “Start the Server”bun run devThe OAuth server will be available at http://localhost:3000.
OAuth Endpoints
Section titled “OAuth Endpoints”GET /oauth/authorize- Authorization endpointPOST /oauth/token- Token endpointPOST /oauth/token/verify- Token introspectionPOST /oauth/token/revoke- Token revocationPOST /oauth/register- Client registrationGET /oauth/clients- List clientsPUT /oauth/clients/:id- Update clientDELETE /oauth/clients/:id- Delete client
Testing
Section titled “Testing”Run the comprehensive test suite:
# Backend tests (OAuth flow and admin)bun test tests/integration/oauth-flow.test.tsbun test tests/integration/oauth-admin.test.tsSecurity Considerations
Section titled “Security Considerations”- Always use HTTPS in production
- Rotate JWT secrets regularly
- Implement rate limiting on auth endpoints
- Store client secrets securely (use bcrypt hashing)
- Enable CORS only for trusted origins
- Set appropriate token expiration times