feat: add optional bearer token authentication#10
Open
russellb wants to merge 1 commit intocassiofb-dev:masterfrom
Open
feat: add optional bearer token authentication#10russellb wants to merge 1 commit intocassiofb-dev:masterfrom
russellb wants to merge 1 commit intocassiofb-dev:masterfrom
Conversation
Implement API token authentication using FastAPI's built-in security utilities. When the API_TOKENS environment variable is set, all API endpoints require a valid bearer token. Implementation details: - New src/auth.py module handles token validation - Uses FastAPI's HTTPBearer security scheme for OpenAPI integration - API_TOKENS env var accepts comma-separated list of valid tokens - Uses secrets.compare_digest for constant-time token comparison to prevent timing attacks - Returns 401 with WWW-Authenticate header on auth failure - When API_TOKENS is not set or empty, authentication is disabled (backwards compatible) - Applied as global dependency, protecting all API routes - /docs endpoint remains accessible for API documentation Usage: # Without auth (development) uvicorn src.api:app --reload # With auth (production) API_TOKENS="token1,token2" uvicorn src.api:app # Making authenticated requests curl -H "Authorization: Bearer token1" http://localhost:8000/top_players/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@russellb is attempting to deploy a commit to the cassiofbdev's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for the project! I wanted to use it, but decided to run my own instance to avoid potential overuse of yours. Since I'm running my own, I wanted to put some basic authentication in place, so I made this addition to support configuring 1 or more API tokens. If the
API_TOKENSenv var is not set, the behavior is unchanged.Implement API token authentication using FastAPI's built-in security utilities. When the API_TOKENS environment variable is set, all API endpoints require a valid bearer token.
Implementation details:
Usage:
Without auth (development) uvicorn src.api:app --reload
With auth (production) API_TOKENS="token1,token2" uvicorn src.api:app
Making authenticated requests curl -H "Authorization: Bearer token1" http://localhost:8000/top_players/
🤖 Generated with Claude Code