Overview
Lichess uses OAuth2 for API authentication. You’ll need an OAuth token to:- Access private user data
- Create games or challenges
- Make moves as a bot
- Manage account settings
Many API endpoints work without authentication. Only use OAuth when you need access to protected resources.
Creating an OAuth App
1
Register your application
Go to https://lichess.org/account/oauth/app and create a new OAuth app.Provide:
- Name: Your application name (shown to users)
- Description: What your app does
- Redirect URI: Where users return after authorization
2
Get your credentials
After creating the app, you’ll receive:
- Client ID: Public identifier for your app
- Client Secret: Keep this confidential!
3
Choose your scopes
Request only the permissions your app needs. Available scopes are listed below.
OAuth Scopes
Scopes define what your app can access:Authorization Code Flow
The standard OAuth2 flow for web applications:1
Redirect user to authorization URL
response_type=code(required)client_id- Your app’s client IDredirect_uri- Must match your registered URIscope- Space-separated scope list (URL encoded)state- Random string to prevent CSRF attacks
2
User authorizes your app
Lichess shows the user what permissions you’re requesting. They can approve or deny.
3
Receive authorization code
User is redirected back to your app:Verify the
state parameter matches what you sent.4
Exchange code for access token
POST to token endpoint:Response:
Personal API Tokens
For personal scripts or testing, create a personal token:- Go to https://lichess.org/account/oauth/token
- Select required scopes
- Click “Create”
- Copy your token (starts with
lip_)
Using Access Tokens
Include the token in theAuthorization header:
Token Expiration
- OAuth tokens expire after 1 year by default
- Personal tokens don’t expire unless revoked
- Expired tokens return
401 Unauthorized - Request a new token when needed (no refresh tokens)
Revoking Tokens
Users can revoke your app’s access at https://lichess.org/account/oauth/token. When a token is revoked:- API requests return
401 Unauthorized - Your app should handle this gracefully
- Prompt the user to re-authorize if needed
Security Best Practices
Store tokens securely
Store tokens securely
- Never expose tokens in client-side code
- Use environment variables or secure key storage
- Encrypt tokens in your database
- Never commit tokens to version control
Use HTTPS
Use HTTPS
- Always use HTTPS for OAuth redirects
- Never send tokens over unencrypted connections
- Validate SSL certificates
Validate state parameter
Validate state parameter
- Generate a random state value for each authorization request
- Store it in the user’s session
- Verify it matches when receiving the callback
- This prevents CSRF attacks
Request minimum scopes
Request minimum scopes
- Only request permissions you actually need
- Users are more likely to approve limited access
- Reduces damage if tokens are compromised
Testing
Use personal tokens for development:Common Errors
Next Steps
API Overview
Learn about API structure and response formats
Rate Limits
Understand rate limiting policies
Bot API
Build a chess bot with OAuth
User Profile
Fetch authenticated user data

