Skip to content

Instantly share code, notes, and snippets.

@sebastienlevert
Last active July 6, 2022 19:50
Show Gist options
  • Save sebastienlevert/2777f24d792afef90a661492ed65fbcb to your computer and use it in GitHub Desktop.
Save sebastienlevert/2777f24d792afef90a661492ed65fbcb to your computer and use it in GitHub Desktop.
Auth sample for Microsoft Graph PHP SDK 2.0.0-RC5
// v1.x
$accessToken = getAccessToken(); // custom token retrieval method
$graph = new Graph();
$graph->setAccessToken($accessToken);


$graph ->createRequest('GET', '/me')
       ->setAccessToken(getAccessToken()) //after initial token expires
        ...

// v2.0-RC
$tokenRequestContext = new AuthorizationCodeContext(
    'tenantId',
    'clientId',
    'clientSecret',
    'authCode',
    'redirectUri'
);
$scopes = ['User.Read', 'Mail.Read'];
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment