Skip to main content

OAuth Provider Overview

The S-Auth OAuth Provider is a fully compliant OAuth2 authorization server built on Cloudflare Workers with D1 database storage.

Supported Grant Types

Grant TypeUse CaseRequires User
Authorization CodeWeb applications, SPAsYes
Authorization Code + PKCEMobile apps, public clientsYes
Client CredentialsService-to-serviceNo
Refresh TokenToken renewalDepends

Endpoints

EndpointDescription
GET /authorizeStart authorization flow
POST /tokenExchange code/credentials for tokens
GET /userinfoGet authenticated user information
POST /revokeRevoke access or refresh tokens
GET /.well-known/openid-configurationOpenID Connect discovery

Token Types

Access Token

  • Prefix: sat_ (S-Auth Token)
  • Default expiry: 15 minutes (900 seconds)
  • Used to access protected resources

Refresh Token

  • Prefix: srt_ (S-Auth Refresh Token)
  • Default expiry: 30 days
  • Used to obtain new access tokens

Scopes

S-Auth supports the following OAuth2 scopes:

ScopeDescription
openidRequired for OIDC flows
profileAccess to user's name and user_id
emailAccess to user's email address

Client Types

Confidential Clients

  • Can securely store a client secret
  • Examples: Server-side web applications
  • Use client_secret_basic or client_secret_post authentication

Public Clients

  • Cannot securely store secrets
  • Examples: SPAs, mobile apps, CLI tools
  • Must use PKCE for security

Security Features

  • PKCE Support - Proof Key for Code Exchange for public clients
  • One-Time Auth Codes - Authorization codes are invalidated after use
  • Token Binding - Tokens are bound to the client that requested them
  • Secure Token Generation - Uses crypto.getRandomValues() for all tokens
  • Password Hashing - bcrypt with configurable cost factor
  • CORS Protection - Configurable allowed origins

Configuration

Token lifetimes and other settings are configured via environment variables:

ACCESS_TOKEN_EXPIRES_IN=900      # 15 minutes
REFRESH_TOKEN_EXPIRES_IN=2592000 # 30 days
AUTH_CODE_EXPIRES_IN=600 # 10 minutes
SESSION_EXPIRES_IN=86400 # 24 hours
BCRYPT_ROUNDS=10 # Password hashing cost

OpenID Connect Discovery

The provider exposes a standard OIDC discovery endpoint at /.well-known/openid-configuration:

{
"issuer": "https://auth.sebbyk.net",
"authorization_endpoint": "https://auth.sebbyk.net/authorize",
"token_endpoint": "https://auth.sebbyk.net/token",
"userinfo_endpoint": "https://auth.sebbyk.net/userinfo",
"revocation_endpoint": "https://auth.sebbyk.net/revoke",
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code", "client_credentials", "refresh_token"],
"code_challenge_methods_supported": ["S256", "plain"],
"scopes_supported": ["openid", "profile", "email"],
"token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post"],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256"]
}