Fix Microsoft JWT validation during Azure key rotation (refresh JWKS + retry on unknown kid)#1425
Merged
atymic merged 1 commit intoSocialiteProviders:masterfrom Mar 23, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves Microsoft id_token JWT validation reliability during Azure AD / Entra ID signing key rotation by caching discovery/JWKS data and retrying signature verification once when encountering an unknown kid.
Changes:
- Add short-lived caching for OpenID configuration and JWKS (with in-memory + optional Laravel Cache support).
- On JWT decode failure due to unknown
kid, force-refresh JWKS (no-cache headers) and retry validation once. - Document the ID token validation + key rollover behavior in the Microsoft provider README.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Microsoft/Provider.php | Adds OpenID/JWKS caching and a one-time JWKS refresh + retry when kid lookup fails during JWT validation. |
| src/Microsoft/README.md | Documents how ID token validation behaves during Microsoft key rollover. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Fixes intermittent Microsoft SSO failures introduced in
socialiteproviders/microsoft4.7.0 whereid_tokenvalidation can fail during Azure AD / Entra ID signing key rotation if the token’skidis not present in the currently published JWKS.Fixes #1402.
Background / Bug
Starting in 4.7.0 the provider validates the
id_tokensignature usingfirebase/php-jwt+ JWKS fetched from the OpenID discovery document. During Microsoft key rollovers there can be a brief window where:kid = X)kid = Xis not yet available (or no longer available) in the JWKS endpointfirebase/php-jwtthrows an exception (e.g."kid" invalid, unable to lookup correct key)What changed
kid, force-refresh the JWKS (withCache-Control: no-cache) and retry validation once before failing.Behavior / Compatibility
Verification
vendor/bin/parallel-lint src/Microsoft