OAuth2 Google Provider
Google OAuth 2.0 provider for The PHP League's OAuth 2.0 Client
Repository Health
Technical Analysis
league/oauth2-google adds Google OAuth 2.0 support to The PHP League’s widely used OAuth 2.0 Client. It implements the Google-specific provider so PHP applications can authenticate users with their Google accounts, exchange authorization codes for access tokens, refresh tokens, and fetch the authenticated user’s Google profile.
As an official League package it follows PSR-1/PSR-2/PSR-4 standards and plugs directly into the generic oauth2-client abstractions, giving you a consistent, well-tested integration for Google sign-in and API access.
What You Get
- A
Googleprovider class compatible with league/oauth2-client - Authorization URL generation with configurable scopes and hosted-domain options
- Authorization-code to access-token exchange and token refresh
- Retrieval of the authenticated user’s Google profile as a resource owner
- PSR-compliant, standards-based integration maintained by The PHP League
Common Use Cases
- Adding ‘Sign in with Google’ to a PHP web application
- Obtaining access tokens to call Google APIs on a user’s behalf
- Restricting login to a specific Google Workspace hosted domain
- Building unified social login alongside other League OAuth providers
Under The Hood
Architecture - The core is src/Provider/Google.php, extending oauth2-client’s AbstractProvider. It defines Google’s authorization, token, and resource-owner (userinfo) endpoints, maps returned claims into a GoogleUser resource owner, and adds Google-specific options like hostedDomain and accessType. A dedicated exception under src/Exception handles Google API error responses.
Tech Stack - Pure PHP built on league/oauth2-client, following PSR-1/PSR-2/PSR-4. Tests run under PHPUnit with code coverage reporting.
Code Quality - The package ships a PHPUnit test suite with Codecov coverage and CI via GitHub Actions, and its small, focused surface makes the provider easy to audit.
API Design - Because it conforms to the oauth2-client provider contract, its API is identical to every other League provider: construct the provider with client id/secret/redirect, call getAuthorizationUrl, getAccessToken, and getResourceOwner, which keeps onboarding trivial for anyone already using the ecosystem.