Skip to main content

Google OAuth

The sunholo.auth.oauth module provides a Google OAuth2 flow with token caching and credential refresh.

GoogleAuthManager

from sunholo.auth.oauth import GoogleAuthManager

auth = GoogleAuthManager(
client_id="your-client-id.apps.googleusercontent.com",
client_secret="your-client-secret",
scopes=["openid", "email", "profile"],
redirect_uri="http://localhost:8000/callback",
)

Get Authorization URL

auth_url = auth.get_authorization_url(state="random-state-token")
# Redirect user to auth_url

Exchange Code for Credentials

# In your callback handler
credentials = await auth.exchange_code(code="auth-code-from-callback")

Get or Refresh Credentials

# Automatically handles token refresh
credentials = await auth.get_credentials(user_id="user@example.com")

Token Caching

Tokens are cached in memory with automatic refresh on expiry. For persistent caching across restarts, you can provide a custom token store.

Sunholo Multivac

Get in touch to see if we can help with your GenAI project.

Contact us

Other Links

Sunholo Multivac - GenAIOps

Copyright ©

Holosun ApS 2026