2017 © Pedro Peláez
 

library microsoft-graph

The Microsoft Graph SDK for PHP

image

microsoft/microsoft-graph

The Microsoft Graph SDK for PHP

  • Wednesday, July 25, 2018
  • by graphsdkpub
  • Repository
  • 27 Watchers
  • 79 Stars
  • 89,816 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 30 Forks
  • 12 Open issues
  • 21 Versions
  • 31 % Grown

The README.md

Get started with the Microsoft Graph SDK for PHP

Build Status Latest Stable Version Total Downloads PHP Version Require, (*1)

Install the SDK

You can install the PHP SDK with Composer by editing your composer.json file:, (*2)

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

Get started with Microsoft Graph

Register your application

Register your application to use the Microsoft Graph API using Microsoft Azure Active Directory in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants., (*3)

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., (*4)

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., (*5)

The following sample creates a TokenRequestContext that gets access without a user:, (*6)

<?php
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;

$tokenRequestContext = new ClientCredentialContext(
    'tenantId',
    'clientId',
    'clientSecret'
);

To gets access on behalf of a user:, (*7)

<?php
use Microsoft\Kiota\Authentication\Oauth\AuthorizationCodeContext;
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider;

$tokenRequestContext = new AuthorizationCodeContext(
    'tenantId',
    'clientId',
    'clientSecret',
    'authCode',
    'redirectUri'
);

Note that your application will need to handle redirecting the user to the Microsoft Identity login page to get the authorization_code that's passed into the AuthorizationCodeContext. See for more on the authorization_code grant flow. To keep your user signed in across multiple requests within a session, see section on access token management, (*8)

Initialize a GraphServiceClient

Using the Token Request Context and optional scopes, a GraphServiceClient can be initialised:, (*9)

use Microsoft\Graph\GraphServiceClient;

// Defaults to using https://graph.microsoft.com/.default scopes
$graphServiceClient = new GraphServiceClient($tokenRequestContext);

// With specific scopes
$scopes = ['User.Read', 'Mail.ReadWrite'];
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

To initialize the GraphServiceClient with an already acquired access token or to retrieve the access token that the SDK fetches on your behalf, see section on access token management., (*10)

For more on Graph client configuration, see more examples, (*11)

Call Microsoft Graph using the v1.0 endpoint and models

The following is an example that shows how to fetch a user from Microsoft Graph, (*12)

<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;

$tokenRequestContext = new ClientCredentialContext(
    'tenantId',
    'clientId',
    'clientSecret'
);
$graphServiceClient = new GraphServiceClient($tokenRequestContext);

try {
    $user = $graphServiceClient->users()->byUserId('[userPrincipalName]')->get()->wait();
    echo "Hello, I am {$user->getGivenName()}";

} catch (ApiException $ex) {
    echo $ex->getError()->getMessage();
}

Note: The SDK is designed to make async requests by default. Operations (get(), post()...) return a Promise. To get the result, call wait() after the operation. Example: ->get()->wait();, (*13)

Note that to calling me() requires a signed-in user and therefore delegated permissions (obtained using the authorization_code flow):, (*14)

<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Authentication\Oauth\AuthorizationCodeContext;

$tokenRequestContext = new AuthorizationCodeContext(
    'tenantId',
    'clientId',
    'clientSecret',
    'authCode',
    'redirectUri'
);
$scopes = ['User.Read'];
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

try {
    $user = $graphServiceClient->me()->get()->wait();
    echo "Hello, I am {$user->getGivenName()}";
} catch (ApiException $ex) {
    echo $ex->getError()->getMessage();
}

Documentation and resources

Upgrading

For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our Upgrade Guide, (*18)

Develop

Run Tests

Run shell vendor/bin/phpunit from the base directory., (*19)

Issues

View or log issues on the Issues tab in the repo., (*20)

Contribute

Please read our Contributing guidelines carefully for advice on how to contribute to this repo., (*21)

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license., (*22)

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments., (*23)

The Versions

25/07 2018

dev-fix85

dev-fix85 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/04 2018

dev-dev

dev-dev https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/04 2018

1.3.0

1.3.0.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/04 2018

dev-pr/79-patch

dev-pr/79-patch https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/04 2018

dev-pr/79

dev-pr/79 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/04 2018

dev-revert-79-patch-5

dev-revert-79-patch-5 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

25/04 2018

dev-beta

dev-beta https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

16/03 2018

dev-master

9999999-dev https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

16/03 2018

1.2.0

1.2.0.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

09/03 2018

dev-march-updates

dev-march-updates https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

30/01 2018

dev-download-bugfix

dev-download-bugfix https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

27/09 2017

dev-functional-bugfix

dev-functional-bugfix https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

25/09 2017

1.1.1

1.1.1.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

31/08 2017

dev-guzzle-proxy

dev-guzzle-proxy https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

08/08 2017

dev-september-updates

dev-september-updates https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

08/08 2017

1.0.3

1.0.3.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

12/07 2017

1.0.2

1.0.2.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

11/05 2017

1.0.1

1.0.1.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

10/05 2017

1.0.0

1.0.0.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

02/03 2017

0.1.1

0.1.1.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales

15/12 2016

0.1.0

0.1.0.0 https://graph.microsoft.io/en-us/

The Microsoft Graph SDK for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Caitlin Bales