OAuth2 Google Provider

Google OAuth 2.0 provider for The PHP League's OAuth 2.0 Client

SDK
Composer
v5.0.0
425stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity8
Maintenance0
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality84
Innovation70
Learning Curve86

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 Google provider 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search