ushka.auth.flow
The built-in login routes: /auth/<provider>/login and /auth/<provider>/callback.
The flow, step by step:
login: randomstate, PKCE verifier and (OpenID Connect)nonceare made withsecretsand kept in the session, together with thenextpage the visitor asked for, validated before it is stored. Then a redirect to the provider.callback: the stored flow is removed from the session first (it works once),stateis 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 storednext.@app.on_loginhooks 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) -> strdef callback_path
def callback_path(config: Any, name: str) -> strWhere the provider sends the browser back: [oauth] callback_path ({provider} filled in), else <prefix>/<name>/callback.
def session_key
def session_key(config: Any) -> strdef after_login
def after_login(config: Any) -> strdef error_path
def error_path(config: Any) -> strdef redirect_origin
def redirect_origin(request: Request | None, config: Any) -> str | NoneWhere 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) -> Nonedef install_piece
def install_piece(app: Ushka) -> Noneinstall 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) -> NoneRegisters the login and callback routes of every provider that has credentials (yours win).