Use the Authentication Provider in v2.0.0
mainVersion 2.0.0 introduces an Authentication Provider that handles token fetching, caching, and refreshing automatically. It wraps around the PHP League's OAuth 2.0 client via GraphPhpLeagueAuthenticationProvider.
Supported flows include client_credentials, authorization_code, and on_behalf_of. It also supports certificate-based authentication.
In v1.x, you had to manually manage access tokens and pass them to the client or individual requests. In v2.0, you initialize a TokenRequestContext and pass it to the provider.
// v2.0 implementation
$tokenRequestContext = new AuthorizationCodeContext(
'tenantId',
'clientId',
'clientSecret',
'authCode',
'redirectUri'
);
$scopes = ['User.Read', 'Mail.Read'];
$authProvider = new GraphPhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);