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

Auth Laravel Package

google/auth

Official Google Auth library for PHP. Implements OAuth 2.0 and Application Default Credentials (ADC) for authenticating to Google APIs and Google Cloud. Install via Composer and use with HTTP clients like Guzzle to authorize API calls.

View on GitHub
Deep Wiki
Context7

google/auth is Google’s officially supported PHP library for OAuth 2.0 authorization and authentication across Google APIs. It provides a robust, standards-based way to obtain and manage access tokens, designed to work cleanly with common HTTP clients in PHP apps.

Built around Application Default Credentials (ADC), it simplifies authenticating in local development, CI, and Google Cloud runtimes while encouraging secure handling of externally supplied credential configurations.

  • Implements Application Default Credentials (ADC) for PHP
  • Supports OAuth 2.0 flows and token acquisition for Google APIs
  • Integrates with Guzzle (e.g., HandlerStack) for authenticated requests
  • Works across environments (local, servers, and Google Cloud)
  • Includes guidance for secure credential validation
Frequently asked questions about Auth
How do I integrate google/auth with Laravel’s HTTP client for Google API calls?
Use Laravel’s HTTP facade with Guzzle middleware. Bind the auth client in a service provider, then call APIs like this: `Http::withOptions(['auth' => 'google_auth'])->get('https://www.googleapis.com/drive/v3/files')`. The library works natively with Guzzle, which Laravel’s HTTP client uses under the hood.
What’s the best way to store Google service account credentials in Laravel?
Use Laravel’s `.env` file for development (e.g., `GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json`) or Laravel Vault for production. Avoid hardcoding credentials. For distributed apps, consider Google Cloud Secret Manager via environment variables or a dedicated secrets manager like HashiCorp Vault.
Does google/auth support OAuth 2.0 for user authentication (e.g., Google Sign-In) in Laravel?
Yes, but pair it with Laravel Socialite for full OAuth flows. The `google/auth` library handles token management and API calls, while Socialite handles the authorization code exchange. Example: Use `GoogleUser::find($googleId)` after Socialite redirects back to your app.
How do I handle token refreshes and caching in a Laravel queue job?
Leverage Laravel’s queue system for async token refreshes. Cache tokens in Redis (PSR-6 compliant) with a TTL (e.g., 55 minutes for OAuth 2.0). Use `Cache::store('redis')->put('google_token', $token, now()->addMinutes(55))` and implement a fallback retry logic with exponential backoff.
Can I use google/auth with Laravel Forge or shared hosting environments?
Yes, but ensure your hosting supports environment variables (e.g., `GOOGLE_APPLICATION_CREDENTIALS`). For shared hosting, avoid ADC and use explicit service account credentials. Test with `ApplicationDefaultCredentials::getCredentials()` to confirm your environment supports it.
What Laravel versions are compatible with google/auth, and are there breaking changes?
The library supports PHP 8.1+ and Laravel 9+. Monitor for breaking changes like OAuth 2.1 migration (RFC 9126). Test with `composer require google/auth --dev` and check the [changelog](https://github.com/googleapis/google-auth-library-php/blob/main/CHANGELOG.md) for version-specific notes.
How do I implement Workload Identity Federation for AWS/Azure in Laravel?
Configure your OIDC provider in Google Cloud IAM, then use `ApplicationDefaultCredentials::getCredentials()` with the `workload_identity_pool_provider` flag. Bind the provider ID and audience in Laravel’s config, e.g., `GOOGLE_WORKLOAD_IDENTITY_PROVIDER='projects/123/locations/global/workloadIdentityPools/my-pool/providers/my-provider'`.
Are there alternatives to google/auth for Laravel Google API integrations?
For OAuth flows, consider Laravel Socialite with `socialiteproviders/google`. For server-to-server auth, `google/auth` is the official choice. Alternatives like `google/apiclient` are outdated and lack ADC support. Stick with `google/auth` for security compliance and Laravel ecosystem alignment.
How do I debug authentication errors like `403 Forbidden` or `invalid_grant` in Laravel?
Enable Guzzle debug mode: `Http::withOptions(['debug' => true, 'auth' => 'google_auth'])->get(...)` to inspect headers. Check token validity with `ApplicationDefaultCredentials::getCredentials()->isAccessTokenExpired()`. For IAM issues, verify service account roles in Google Cloud Console.
Can I use google/auth with Laravel’s Horizon for long-running Google API jobs?
Yes, but manage token lifecycles carefully. Offload token refreshes to queues with `dispatch(new RefreshGoogleTokenJob())`. Use `Cache::remember()` to avoid redundant refreshes. For Cloud Run or serverless, ensure your environment supports ADC or explicit credentials.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport