Refactor Microsot Auth into a testable class with expanded error handling#1500
Open
barakiva wants to merge 5 commits into
Open
Refactor Microsot Auth into a testable class with expanded error handling#1500barakiva wants to merge 5 commits into
barakiva wants to merge 5 commits into
Conversation
…ng of azure's 'error' whereas before failures would be silent. Assisted-By:claude-code-sonnet-4.6
…ime on the upstream when making PRs
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Microsoft OAuth2 callback endpoint into a dedicated handler/value-object pair to support both success and error callback shapes, improve diagnostics, and make the logic unit-testable.
Changes:
- Extract callback parsing/redirect resolution into
MicrosoftOAuthCallback+MicrosoftOAuthCallbackResult. - Log and redirect on Azure error responses rather than silently failing.
- Add unit tests for success/error/missing params and URL encoding; enable
workflow_dispatchfor CI workflows.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| Web/microsoft-auth.php | Uses the new callback handler and adds error logging before redirecting. |
| lib/Application/Authentication/MicrosoftOAuthCallback.php | Introduces the callback handler and result value object for success/error outcomes. |
| tests/Application/Authentication/MicrosoftOAuthCallbackTest.php | Adds unit tests covering success, encoding, and error/missing-params behavior. |
| .github/workflows/phpunit.yml | Adds manual workflow trigger (workflow_dispatch). |
| .github/workflows/lint-and-analyse-php.yml | Adds manual workflow trigger (workflow_dispatch). |
| .github/workflows/integration-tests.yml | Adds manual workflow trigger (workflow_dispatch). |
| .github/workflows/docs.yml | Adds manual workflow trigger (workflow_dispatch). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
Applied all code reivew suggestions and unit tests all pass. |
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.
Summary
Web/microsoft-auth.phppreviously handled only the success path ofMicrosoft's OAuth 2.0 authorization code flow. Per the Microsoft identity
platform docs, the callback endpoint receives two distinct response shapes:
?code=...&state=...?error=...&error_description=...Error responses were silently ignored — the page would redirect to
Webwith noerrorheader, causing a confusing failuredownstream with no diagnostic information.
Changes
MicrosoftOAuthCallback(lib/Application/Authentication/)with a
MicrosoftOAuthCallbackResultvalue object representing the twooutcome cases. This makes the code more testable.
error-takes-precedence-over-code, and missing params
workflow_dispatchtrigger to CI workflows to allow manual runs on forks so contributors can make sure PRs will pass CI before submitting to upstreamNot addressed in this PR
stateparameter verification — the Microsoft docs recommend verifying thereturned
statematches the value sent in the authorization request as aCSRF mitigation. This would require storing the state server-side before the
redirect, which is a larger change.
Any feedback on testing & class design would be appreicated.