Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Google Api Laravel Package

tomshaw/google-api

Laravel Google OAuth 2.0 service client with configurable token storage (DB or custom), published config, and migrations. Integrates google/apiclient-services and supports Composer cleanup to include only the Google APIs you need (e.g., Gmail, Calendar).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Laravel-Native Integration: The package is designed specifically for Laravel (v13+) and PHP 8.5, aligning with modern Laravel ecosystems. It leverages Laravel’s service container, dependency injection, and configuration system seamlessly.
    • Modular Design: Supports selective loading of Google API services (e.g., Gmail, Calendar, Drive) via composer.json, reducing bloat and improving performance.
    • Extensible Storage: Custom token storage adapters (e.g., database, Redis, file) can be implemented via StorageAdapterInterface, enabling flexibility for different deployment scenarios (e.g., serverless, microservices).
    • Fluent API: Service adapters (e.g., GoogleCalendar, GoogleGmail) provide intuitive, method-chained interfaces for common operations (e.g., createEvent(), sendEmail()), reducing boilerplate.
    • OAuth 2.0 Best Practices: Configurable prompts (consent, auto), offline access, and scope management align with Google’s OAuth guidelines and security requirements.
  • Cons:

    • Tight Coupling to Google APIs: The package abstracts Google’s API client but doesn’t provide a generic OAuth2 layer for non-Google providers, limiting reuse for other identity providers.
    • Laravel-Specific Abstractions: Features like database token storage assume Laravel’s Eloquent/Query Builder, which may not translate cleanly to non-Laravel PHP applications.
    • Limited Async Support: The package doesn’t explicitly support asynchronous operations (e.g., queues, Promises), which could be a bottleneck for high-latency APIs like Drive or Gmail.

Integration Feasibility

  • Laravel Compatibility:
    • High: Explicitly supports Laravel 13 and PHP 8.5. The package uses Laravel’s service providers, config publishing, and dependency injection, ensuring smooth integration.
    • Migration Path: If upgrading from older Laravel versions, the package’s composer.json constraints (PHP 8.5+) may require a full-stack upgrade, but the changelog shows active maintenance for Laravel 13.
  • Google API Services:
    • Selective Loading: The composer.json extra field (google/apiclient-services) allows opting into only required services (e.g., Gmail, Calendar), reducing deployment size and complexity.
    • Service-Specific Adapters: Pre-built adapters for Calendar, Gmail, Drive, and Books abstract away low-level API calls, but custom services require manual implementation of GoogleApiAccessorInterface.
  • Authentication Flow:
    • OAuth 2.0: The package handles the OAuth flow (auth URLs, token exchange) with configurable prompts and scopes. However, the TPM must ensure compliance with Google’s OAuth consent screen policies (e.g., verified domains, privacy policy links).

Technical Risk

  • Dependencies:
    • Google API Client: The package wraps google/apiclient, which is actively maintained but may introduce breaking changes. The package’s changelog shows version adjustments (e.g., 0.7.1), indicating vigilance is needed.
    • Laravel Version Lock: The strict PHP/Laravel version requirements (8.5/13) could pose risks if the project’s tech stack lags behind or needs to downgrade.
  • Token Management:
    • Storage Risks: Database storage (default) requires a migration and assumes Laravel’s ORM. Custom adapters (e.g., Redis) must be implemented carefully to avoid token leakage or race conditions.
    • Token Revocation: The deleteAccessToken method exists but may need custom logic for handling Google’s token revocation APIs or user logout flows.
  • Performance:
    • Initial Load: Loading all 200+ Google API services upfront is avoided via selective loading, but each service still pulls its dependencies (e.g., google/apiclient-services for Gmail).
    • Rate Limiting: Google APIs enforce quotas and rate limits. The package doesn’t include built-in retry logic or exponential backoff, which the TPM must address (e.g., via Laravel’s retry helper or a custom middleware).

Key Questions

  1. Authentication Scope:

    • Are the required Google API scopes (e.g., https://www.googleapis.com/auth/calendar) already approved in the Google Cloud Console? Unapproved scopes will fail OAuth flows.
    • How will user consent be handled for scopes beyond the initial authorization (e.g., dynamic scope requests)?
  2. Token Storage:

    • Is database storage acceptable, or are alternative adapters (e.g., Redis, cache) preferred for scalability? If custom, does the team have capacity to implement StorageAdapterInterface?
    • How will token refreshes be handled during application scaling (e.g., stateless vs. stateful sessions)?
  3. Error Handling:

    • How will Google API errors (e.g., 403 Forbidden, 429 Too Many Requests) be surfaced to users? The package lacks built-in error translation.
    • Are there plans to integrate with Laravel’s error handling (e.g., custom exception handlers)?
  4. Testing:

    • How will OAuth flows be tested in CI/CD (e.g., mocking auth codes, using service accounts for testing)?
    • Are there plans to add integration tests for Google API responses (e.g., mocking API calls with Mockery or VCR recordings)?
  5. Monitoring:

    • How will API usage (e.g., quota limits, errors) be monitored? Google provides usage reports, but integration would require custom logic.
    • Are there plans to log OAuth token metadata (e.g., expiration times) for debugging?
  6. Security:

    • How will the Google API credentials file (auth_config) be secured (e.g., environment variables, secrets manager)? The package doesn’t enforce encryption or access controls.
    • Is there a need for role-based access control (RBAC) for Google API operations (e.g., only admins can manage Calendar events)?
  7. Future-Proofing:

    • How will the package be updated if Google deprecates APIs or changes OAuth flows (e.g., OAuth 2.1)?
    • Are there plans to support Google’s Service Account Impersonation for server-to-server auth?

Integration Approach

Stack Fit

  • Primary Fit:
    • Laravel Applications: Ideal for Laravel 13+ projects requiring Google API integrations (e.g., SSO, Calendar sync, Gmail notifications).
    • PHP 8.5+: Leverages modern PHP features (e.g., typed properties, enums) for better performance and maintainability.
  • Secondary Fit:
    • Microservices: Can be adapted for non-Laravel PHP apps by implementing custom storage adapters and bypassing Laravel-specific features (e.g., config publishing).
    • Serverless: With Redis or cache-based token storage, the package could work in serverless environments (e.g., AWS Lambda + Laravel Vapor).
  • Non-Fit:
    • Non-PHP Stacks: Not applicable for Node.js, Python, or Go projects.
    • Legacy Laravel: Versions <13 or PHP <8.5 will require significant refactoring or polyfills.

Migration Path

  1. Prerequisites:

    • Upgrade Laravel to v13 and PHP to 8.5 if not already done.
    • Set up a Google Cloud Project and enable the required APIs (e.g., Calendar API).
    • Download OAuth 2.0 credentials from the Google Cloud Console (JSON key file).
  2. Installation:

    composer require tomshaw/google-api
    php artisan vendor:publish --provider="TomShaw\GoogleApi\Providers\GoogleApiServiceProvider" --tag=config
    
    • Configure config/google-api.php with:
      • auth_config: Path to the downloaded JSON credentials file.
      • service_scopes: Array of required scopes (e.g., ['https://www.googleapis.com/auth/calendar']).
      • token_storage_adapter: Defaults to DatabaseTokenStorage; override for custom storage.
  3. Selective Service Loading:

    • Update composer.json to opt into only needed services:
      "extra": {
        "google/apiclient-services": ["Gmail", "Calendar"]
      }
      
    • Run composer dump-autoload to clean up unused services.
  4. Database Migration (Optional):

    • If using DatabaseTokenStorage, run:
      php artisan migrate
      
    • This creates a google_api_tokens table for storing OAuth tokens.
  5. Authentication Flow:

    • Implement routes/controllers for OAuth:
      // Redirect user to Google for auth
      route('google.auth', [GoogleAuthController
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle