Microsoft Graph SDK for PHP

The official PHP SDK for calling the Microsoft Graph API across Microsoft 365 services.

SDK
Composer
vv3.5.0
668stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity84
Maintenance84
Community84
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture88
Code Quality82
Innovation84
Learning Curve60

The Microsoft Graph SDK for PHP is the official client library for the Microsoft Graph REST API, the single endpoint that exposes data and intelligence across Microsoft 365, Entra ID, Outlook, Teams, OneDrive, SharePoint, and more. It provides a fluent, strongly typed request builder generated from the Graph metadata, along with authentication providers for the standard OAuth 2.0 flows.

Built on the Kiota abstractions and PHP League OAuth libraries, the SDK handles token acquisition, caching, and refresh under the hood, letting you focus on the resources you want to read or write. Requests are issued asynchronously and return promises, and every response is deserialized into typed model objects that mirror the Graph schema.

What You Get

  • A GraphServiceClient with fluent request builders covering the full Microsoft Graph v1.0 API surface
  • Authentication providers for client credentials, authorization code, and on-behalf-of OAuth 2.0 flows
  • Automatic access-token acquisition, caching, and refresh against the Microsoft identity platform
  • Strongly typed model classes generated from the Graph metadata for requests and responses
  • Batch request support and national-cloud (GCC, DoD, China) endpoint configuration

Common Use Cases

  • Reading and sending Outlook mail, calendar events, and contacts on behalf of a user
  • Managing users, groups, and directory objects in Microsoft Entra ID
  • Uploading, downloading, and sharing files in OneDrive and SharePoint
  • Automating Microsoft Teams messages, channels, and membership from a PHP backend

Under The Hood

Architecture - The client is layered: GraphServiceClient (in src/) extends a generated BaseGraphClient whose request builders under src/Generated mirror the Graph URL tree, each delegating HTTP work to a GraphRequestAdapter built on the Kiota abstractions. A TokenRequestContext is wrapped by GraphPhpLeagueAuthenticationProvider, which attaches bearer tokens fetched by the PHP League OAuth2 client before requests flow through the adapter to Graph.

Tech Stack - Written for PHP 8.2+ and distributed as microsoft/microsoft-graph. It depends on microsoft/microsoft-graph-core for the shared adapter, serialization, and authentication plumbing, and transitively on the Kiota abstractions and php-http discovery. PHPUnit drives tests and PHPStan enforces static analysis; the bulk of src is code-generated from the Graph OpenAPI/metadata.

Code Quality - The hand-written surface (GraphServiceClient, BatchRequestBuilder, GraphRequestAdapter) is small and focused, with the vast majority of the tree machine-generated for consistency. Test coverage is intentionally thin (a single GraphServiceClientTest) since generated builders are validated upstream in the Kiota toolchain; the project runs CI validation, PHPStan, and follows PSR-4 autoloading.

API Design - The fluent, resource-mirroring API (e.g. users()->byUserId(’…’)->get()->wait()) is highly discoverable and consistent because it is generated directly from the Graph schema. The promise-based, always-async model adds a small amount of boilerplate (the trailing wait()) but keeps the surface uniform, and authentication setup is reduced to constructing a single token context.

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