Social login (OAuth)
Sign in with Google or GitHub โ no OAuth SDK.
class=kw>import larz.auth as auth, larz.oauth as oauth
auth.enable(app)
oauth.enable(app, providers={
"google": {"client_id": "...", "client_secret": "..."},
"github": {"client_id": "...", "client_secret": "..."},
})
Each provider gets two routes: /larz/oauth/<name>/login (redirects to the
provider with a signed state token) and /larz/oauth/<name>/callback
(verifies state, exchanges the code for a token, fetches the email, logs the user in). Presets
ship for Google and GitHub.
Any OAuth2 provider
oauth.enable(app, providers={"acme": {
"client_id": "...", "client_secret": "...",
"authorize_url": "https://acme.com/oauth/authorize",
"token_url": "https://acme.com/oauth/token",
"userinfo_url": "https://acme.com/api/me",
"scope": "email", "email_field": "email"}})
Custom account handling
By default a successful login finds-or-creates a larz.auth.User by email. Pass
on_login(req, email, profile, provider) to control linking; return a
Response to override the post-login redirect.
The
state parameter is verified on the callback, so the flow is
CSRF-safe. See the guide: Add Google login in Python.