Authentication

Gspace supports two authentication methods: OAuth2 and Service Account.

OAuth2 Authentication

OAuth2 is used for user-facing applications where you need to access user data.

Setting Up OAuth2

  1. Create OAuth2 credentials in Google Cloud Console
  2. Download the credentials JSON file
  3. Initialize Gspace with the credentials:
python
from gspace import GSpace

gspace = GSpace.from_oauth(
    credentials_file="path/to/oauth2-credentials.json",
    scopes=["calendar", "gmail"]
)

First-Time Authorization

On the first run, Gspace will:

  1. Open a browser window for Google authentication
  2. Ask the user to grant permissions
  3. Store the token for future use

Service Account Authentication

Service Accounts are used for server-to-server applications.

Setting Up Service Account

  1. Create a Service Account in Google Cloud Console
  2. Download the service account key JSON file
  3. Initialize Gspace with the service account:
python
from gspace import GSpace

gspace = GSpace.from_service_account(
    service_account_file="path/to/service-account-key.json",
    scopes=["calendar", "gmail"]
)

Scopes

Scopes determine what permissions your application has. Use the GoogleScopes utility class:

python
from gspace.utils.scopes import GoogleScopes

# Get scopes for a service
calendar_scopes = GoogleScopes.get_service_scopes("calendar", "full")
gmail_scopes = GoogleScopes.get_service_scopes("gmail", "readonly")

# Combine scopes
all_scopes = calendar_scopes + gmail_scopes

Token Management

Gspace automatically manages token storage and refresh. Tokens are stored securely and refreshed when needed.

For more advanced token management, see Token Manager in the API reference.