Ushka

ushka.auth.flow

The built-in login routes: /auth/<provider>/login and /auth/<provider>/callback.

The flow, step by step:

  1. login: random state, PKCE verifier and (OpenID Connect) nonce are made with secrets and kept in the session, together with the next page the visitor asked for, validated before it is stored. Then a redirect to the provider.
  2. callback: the stored flow is removed from the session first (it works once), state is compared in constant time, the code is traded for a token by the server (the client secret never reaches the browser), the profile is fetched, the e-mail must be verified and in an allowed domain. Only then the minimal profile goes in the session, the session id is rotated and the visitor is redirected to the stored next. @app.on_login hooks run just before the profile is stored: they may add to it, or refuse the login.

Whatever goes wrong ends in a redirect to [oauth] login_error_path with a short code (?login_error=state); text from the provider is never echoed.

In this module

def domains_of()[oauth] allowed_email_domains, lower case, without a leading @.
def enabled_providers()The providers that have both a client id and a client secret.
def half_configured()Providers with a client id or a secret, but not both.
def prefix_of()
def callback_path()Where the provider sends the browser back: [oauth] callback_path ({provider} filled in), else <prefix>/<name>/callback.
def session_key()
def after_login()
def error_path()
def redirect_origin()Where the provider sends the browser back: [oauth] redirect_base, else the [seo] url rule.
def problems()[(level, message)] for ushka check; level is "error" or "warn".
def check_origin()
def install_piece()install for app.use(Google()): the address is checked at startup, so Seo(url=...) may come later.
def install()Registers the login and callback routes of every provider that has credentials (yours win).

def domains_of

def domains_of(config: Any) -> list[str]

[oauth] allowed_email_domains, lower case, without a leading @.

def enabled_providers

def enabled_providers(config: Any) -> list[str]

The providers that have both a client id and a client secret.

def half_configured

def half_configured(config: Any) -> list[str]

Providers with a client id or a secret, but not both.

def prefix_of

def prefix_of(config: Any) -> str

def callback_path

def callback_path(config: Any, name: str) -> str

Where the provider sends the browser back: [oauth] callback_path ({provider} filled in), else <prefix>/<name>/callback.

def session_key

def session_key(config: Any) -> str

def after_login

def after_login(config: Any) -> str

def error_path

def error_path(config: Any) -> str

def redirect_origin

def redirect_origin(request: Request | None, config: Any) -> str | None

Where the provider sends the browser back: [oauth] redirect_base, else the [seo] url rule.

Never the Host header on its own: see ushka.web.seo.origin_of.

def problems

def problems(config: Any, production: bool = False) -> list[tuple[str, str]]

[(level, message)] for ushka check; level is "error" or "warn".

def check_origin

def check_origin(config: Any) -> None

def install_piece

def install_piece(app: Ushka) -> None

install for app.use(Google()): the address is checked at startup, so Seo(url=...) may come later.

def install

def install(app: Ushka, check: bool = True) -> None

Registers the login and callback routes of every provider that has credentials (yours win).