Larz › Google login in Python

Social login in Python — Google, GitHub, anything

Let users sign in with Google or GitHub without pulling an OAuth SDK. Larz runs the whole authorization-code flow over urllib and finds-or-creates a user for you.

pip install larz
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": "..."},
})
# login links: /larz/oauth/google/login  and  /larz/oauth/github/login

QuickstartGitHubFree course

How it works

Each provider gets a /login route (redirects to the provider with a signed state token) and a /callback route (verifies state, exchanges the code for a token, fetches the user's email, and logs them in). Presets ship for Google and GitHub; any other OAuth2/OIDC provider works by passing its authorize/token/userinfo URLs.

The state parameter is checked on the callback, so the flow is CSRF-safe out of the box. Override on_login to control account creation and linking.

FAQ

Which providers are supported?

Google and GitHub have built-in presets; any OAuth2/OIDC provider works by passing its authorize, token and userinfo URLs.

Do I need an OAuth SDK?

No. Larz performs the authorization-code exchange with urllib, so there is nothing extra to install.

Is the flow secure?

Yes — a signed state token is verified on the callback to prevent CSRF, and tokens are exchanged server-side.