Skip to main content

litestar-oauth

PyPI - Version PyPI - Python Version CI Coverage License - MIT

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
Google 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]

License

MIT License - see LICENSE for details.

Metadata

Release files for litestar-oauth 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for litestar-oauth 0.1.1
File Size Uploaded
litestar_oauth-0.1.1.tar.gz 36.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for litestar-oauth 0.1.1
File Interpreter ABI Platform
litestar_oauth-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 87.6 kB

Release files / litestar_oauth-0.1.1.tar.gz

Download URL litestar_oauth-0.1.1.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
40e4e1f9528f7f653836cb04d2df8be65eb7d01dbb3af971f29b21edecf8a11e
BLAKE2b-256 checksum
How to use checksums
96750600ab46e409ba5e1ea045784db81638513d94d5d42e3ee7ffb7b39854f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release files / litestar_oauth-0.1.1-py3-none-any.whl

Download URL litestar_oauth-0.1.1-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d705764772da15d5d5244f0f58b927b434273f7808a77a932bd1c5df119a053
BLAKE2b-256 checksum
How to use checksums
3992adaf2ca5e0010c8d0c0a112c867fac88d06ab52db5b2e34bca55887f18e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page