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
- Create OAuth2 credentials in Google Cloud Console
- Download the credentials JSON file
- Initialize Gspace with the credentials:
pythonfrom 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:
- Open a browser window for Google authentication
- Ask the user to grant permissions
- Store the token for future use
Service Account Authentication
Service Accounts are used for server-to-server applications.
Setting Up Service Account
- Create a Service Account in Google Cloud Console
- Download the service account key JSON file
- Initialize Gspace with the service account:
pythonfrom 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:
pythonfrom 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.