Add Microsoft Graph token provider with client credentials flow and unit tests#8901
Open
sanjacornelius wants to merge 3 commits into
Open
Add Microsoft Graph token provider with client credentials flow and unit tests#8901sanjacornelius wants to merge 3 commits into
sanjacornelius wants to merge 3 commits into
Conversation
Introduce MicrosoftGraphTokenProvider to obtain and cache OAuth2 client-credentials tokens from Microsoft Graph. The provider validates required credentials, posts to the tenant token endpoint via Guzzle, throws a RuntimeException on missing creds or HTTP errors (propagating server error messages), and caches the access token for ~50 minutes using a server-specific cache key. Includes unit tests that assert exception behavior for missing credentials and mock Guzzle to verify token request parameters and caching behavior.
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Add an optional Guzzle Client dependency to MicrosoftGraphTokenProvider so an HTTP client can be injected for testing. The constructor now accepts ?Client $httpClient and the provider uses $this->httpClient ?? new Client() when posting for tokens. Update the unit test to mock GuzzleHttp\Client (remove overload-based mock and separate-process annotations), import Client, and pass the mocked client into the provider. This enables dependency injection and simpler, more reliable tests.
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Replace Mockery-based response mocks in MicrosoftGraphTokenProviderTest with an actual GuzzleHttp\Psr7\Response instance. Simplifies the test by providing a real PSR-7 response (200) with a JSON body and removes the need to mock getBody()/getContents() and getStatusCode(). Added the Response use statement.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




This PR introduces a MicrosoftGraphTokenProvider to centralize Microsoft Graph OAuth2 client credentials authentication.
The provider is responsible for requesting, caching, and returning access tokens used by Microsoft Graph integrations. It validates the required Azure credentials, retrieves tokens from the Microsoft identity platform, caches them to reduce unnecessary authentication requests, and provides improved error handling when authentication fails.
Unit tests have also been added to verify the provider's behavior across successful and failure scenarios.
Solution
MicrosoftGraphTokenProviderfor Microsoft Graph OAuth2 client credentials authentication.RuntimeExceptionwhen credentials are missing or token requests fail.How to Test
Run the unit tests and verify they all pass:
Related Tickets & Packages
ci:connector-send-email:subtask/FOUR-32164
Code Review Checklist