PHPackages                             microsoft/microsoft-graph - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. microsoft/microsoft-graph

ActiveLibrary[API Development](/categories/api)

microsoft/microsoft-graph
=========================

The Microsoft Graph SDK for PHP

v2.56.0(3mo ago)65923.5M—5%148[78 issues](https://github.com/microsoftgraph/msgraph-sdk-php/issues)[1 PRs](https://github.com/microsoftgraph/msgraph-sdk-php/pulls)20MITPHPPHP ^8.0 || ^7.4CI passing

Since Dec 15Pushed 3d ago37 watchersCompare

[ Source](https://github.com/microsoftgraph/msgraph-sdk-php)[ Packagist](https://packagist.org/packages/microsoft/microsoft-graph)[ Docs](https://developer.microsoft.com/en-us/graph)[ RSS](/packages/microsoft-microsoft-graph/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (219)Used By (20)Security (1)

Get started with the Microsoft Graph SDK for PHP
================================================

[](#get-started-with-the-microsoft-graph-sdk-for-php)

[![Build Status](https://github.com/microsoftgraph/msgraph-sdk-php/actions/workflows/pr-validation.yml/badge.svg)](https://github.com/microsoftgraph/msgraph-sdk-php/actions/workflows/pr-validation.yml/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/42dff75f986203a44061c66716f48d311d25e05eb50cf3d60181c61709ba14ba/687474703a2f2f706f7365722e707567782e6f72672f6d6963726f736f66742f6d6963726f736f66742d67726170682f76)](https://packagist.org/packages/microsoft/microsoft-graph)[![Total Downloads](https://camo.githubusercontent.com/a028c429859f1d29f26c7b7d9fe094bdc286f691a127400df0b187d9767c2f1e/687474703a2f2f706f7365722e707567782e6f72672f6d6963726f736f66742f6d6963726f736f66742d67726170682f646f776e6c6f616473)](https://packagist.org/packages/microsoft/microsoft-graph)[![PHP Version Require](https://camo.githubusercontent.com/bacc80d1da6ad007d266385a8b11bb9e5b1320989547d3fae833dfa0fe0af215/687474703a2f2f706f7365722e707567782e6f72672f6d6963726f736f66742f6d6963726f736f66742d67726170682f726571756972652f706870)](https://packagist.org/packages/microsoft/microsoft-graph)

Install the SDK
---------------

[](#install-the-sdk)

### Prerequisites

[](#prerequisites)

- PHP 8.2 or later (see [PHP supported versions](https://www.php.net/supported-versions.php))

You can install the PHP SDK with Composer by editing your `composer.json` file:

```
{
    "require": {
        // x-release-please-start-version
        "microsoft/microsoft-graph": "^3.1.0"
        // x-release-please-end
    }
}
```

Get started with Microsoft Graph
--------------------------------

[](#get-started-with-microsoft-graph)

### Register your application

[](#register-your-application)

Register your application to use the Microsoft Graph API using [Microsoft Azure Active Directory](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants.

### Create a Token Request Context

[](#create-a-token-request-context)

A Token Request Context contains the credentials used to authenticate requests. The SDK supports various contexts that align with OAuth 2.0 flows: `client_credentials`, `authorization_code` and `on_behalf_of` with support for secret-based and certificate-based client authentication.

Under the hood, the Token Request Context is passed to an authentication provider which fetches, caches and refreshes access tokens ensuring all requests are authenticated against the Microsoft Identity platform.

The following sample creates a TokenRequestContext that [gets access without a user](https://docs.microsoft.com/en-us/graph/auth-v2-service?context=graph%2Fapi%2F1.0&view=graph-rest-1.0):

```
