MS Graph PHP SDK fails to retrieve an access token

Ian Foulds 6 Reputation points

I am using the PHP microsoft/microsoft-graph package version 2.3.0, PHP version 8.2.5.

Following the examples described here:

My code fails when it tries to fetch the token with a malformed request. Only the tenant ID is put into the /token endpoint request, the client_id and other required parameters are not being set on the oauthProvider within PhpLeagueAccessTokenProvider.

Here is my code, as per the example:

        $tokenRequestContext = new AuthorizationCodeContext(
            $this->getAccessToken()->__toString(),	// Actual token or 'AUTH_CODE_FROM_REDIRECT'

        $provider = new GraphServiceClient($tokenRequestContext, self::AZURE_SCOPES);

The nesting of calls ending up in PhpLeagueAccessTokenProvider do not set the required parameters in the oauthProvider on line 94:

        $this->oauthProvider = $oauthProvider ?? ProviderFactory::create($tokenRequestContext);

This merely sets the URLs and does not set the credentials within the provider resulting in an invalid request when calling the /token endpoint.

It looks like I am setting this up correctly according to all the documentation I've read, but the client credentials are just not being set in the requests.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,443 questions
0 comments No comments
{count} votes