OAuth2 authentication plugin for Litestar
Project description
litestar-oauth
OAuth2 authentication plugin for Litestar.
Features
- Async-First Design: Built on httpx for async HTTP operations
- Pre-built Providers: GitHub, Google, Discord, and a generic provider for any OAuth2/OIDC service
- Type-Safe: Full typing with Protocol-based interfaces
- CSRF Protection: Built-in state management to prevent cross-site request forgery
- Automatic Routes: Plugin registers login and callback routes automatically
- Normalized User Data: Consistent user info format across all providers
- Extensible: Easy to add custom providers for any OAuth2-compliant identity provider
Installation
uv add litestar-oauth
Or with pip:
pip install litestar-oauth
Quick Start
from litestar import Litestar
from litestar_oauth.contrib.litestar import OAuthPlugin, OAuthConfig
app = Litestar(
plugins=[
OAuthPlugin(
config=OAuthConfig(
redirect_base_url="https://example.com",
github_client_id="your-client-id",
github_client_secret="your-client-secret",
)
)
],
)
# Routes automatically registered:
# GET /auth/github/login - Redirects to GitHub OAuth
# GET /auth/github/callback - Handles OAuth callback
Standalone Usage
Use the OAuth providers without the Litestar plugin:
from litestar_oauth.providers import GitHubOAuthProvider
provider = GitHubOAuthProvider(
client_id="your-client-id",
client_secret="your-client-secret",
)
# Generate authorization URL
auth_url = provider.get_authorization_url(
redirect_uri="https://example.com/callback",
state="random-state-token",
)
# After callback, exchange code for token
token = await provider.exchange_code(
code="authorization-code",
redirect_uri="https://example.com/callback",
)
# Get user info
user_info = await provider.get_user_info(token.access_token)
print(f"Hello, {user_info.username}!")
Supported Providers
| Provider | Class | Default Scopes |
|---|---|---|
| GitHub | GitHubOAuthProvider |
read:user, user:email |
GoogleOAuthProvider |
openid, email, profile |
|
| Discord | DiscordOAuthProvider |
identify, email |
| Generic | GenericOAuthProvider |
Configurable |
Use GenericOAuthProvider for any OAuth2/OIDC provider like Keycloak, Auth0, Okta, or Azure AD.
Optional Extras
# Apple Sign In (requires JWT signing)
uv add litestar-oauth[apple]
# All provider extras
uv add litestar-oauth[all]
Links
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litestar_oauth-0.1.0.tar.gz.
File metadata
- Download URL: litestar_oauth-0.1.0.tar.gz
- Upload date:
- Size: 33.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4667d9644e6fffa782afe19b28877f553bbff9b942700acfa0484994ae4464e
|
|
| MD5 |
cffda60ad5c06f9b447472094c813814
|
|
| BLAKE2b-256 |
a7c26c08ba4d87efedcaf8e5239990f9d3d39d3c8a1706dbb2adba52112f9fbe
|
Provenance
The following attestation bundles were made for litestar_oauth-0.1.0.tar.gz:
Publisher:
publish.yml on JacobCoffee/litestar-oauth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_oauth-0.1.0.tar.gz -
Subject digest:
e4667d9644e6fffa782afe19b28877f553bbff9b942700acfa0484994ae4464e - Sigstore transparency entry: 763768954
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-oauth@79d87e527f60c6e68c044724d2109764129be459 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79d87e527f60c6e68c044724d2109764129be459 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litestar_oauth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litestar_oauth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fea10d74da2a1c1f7fce947a72dbb822b2fdc8d67b5f5ac4652bc62604c57e65
|
|
| MD5 |
256e61923de7907b83d6c5f1b32cc499
|
|
| BLAKE2b-256 |
9c4162deacb5bfbe87531e5735b84e179f9952032a82bd7c24e310383041a430
|
Provenance
The following attestation bundles were made for litestar_oauth-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on JacobCoffee/litestar-oauth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_oauth-0.1.0-py3-none-any.whl -
Subject digest:
fea10d74da2a1c1f7fce947a72dbb822b2fdc8d67b5f5ac4652bc62604c57e65 - Sigstore transparency entry: 763768955
- Sigstore integration time:
-
Permalink:
JacobCoffee/litestar-oauth@79d87e527f60c6e68c044724d2109764129be459 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/JacobCoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79d87e527f60c6e68c044724d2109764129be459 -
Trigger Event:
release
-
Statement type: