Ushka

ushka.auth

Login with OAuth 2.0 / OpenID Connect: Google and GitHub, no extra dependency.

Configure the provider in [oauth] (the secret in the environment), and Ushka serves /auth/google/login and /auth/google/callback. In your routes:

from ushka import Depends
from ushka.auth import current_user, login_required

@app.get("/account")
async def account(user=Depends(login_required)):
    return f"Hello {user['name']}"

current_user(request) is the profile (provider, sub, email, name, picture) or None, login_url("google", next="/x") is the link for a button and logout(request) ends the session. See the guide: Sign in with Google and GitHub.

In this module

def current_user()The logged-in user's profile (provider, sub, email, name, picture), or None.
def login_url()The path that starts a login with provider, ready for a link or a button.
def login_required_for()Like login_required, but sends visitors to provider: Depends(login_required_for("github")).
def logout()Ends the login: the session is emptied (server-side sessions are revoked).

def current_user

def current_user(request: Request) -> dict[str, str] | None

The logged-in user's profile (provider, sub, email, name, picture), or None.

def login_url

def login_url(
    provider: str,
    next: str | None = None,
    *,
    config: Any = None,
) -> str

The path that starts a login with provider, ready for a link or a button.

next is where the visitor lands afterwards; it is checked again when the login starts, so any value is safe to pass.

def login_required_for

def login_required_for(provider: str)

Like login_required, but sends visitors to provider: Depends(login_required_for("github")).

def logout

def logout(request: Request) -> None

Ends the login: the session is emptied (server-side sessions are revoked).