Add AzureJWTVerifier for Managed Identity token verification#3058
Add AzureJWTVerifier for Managed Identity token verification#3058
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36c250ccad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
WalkthroughAdds a new Azure-specific JWT verifier class and separates advertised OAuth metadata scopes from token validation scopes. TokenVerifier now exposes a scopes_supported property; RemoteAuthProvider accepts an optional scopes_supported parameter and uses it when generating protected-resource metadata. Introduces AzureJWTVerifier that auto-configures JWKS/issuer/audience, supports multi-tenant issuer handling, validates short-form scopes while advertising full-URI scopes, and documents a token-verification-only Managed Identity pattern. Documentation updates add guidance and examples for scope handling and overriding advertised scopes. Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Azure AD has a scope format split: clients request full URI scopes (
api://client-id/read) but tokens contain short-form scopes (readinscp). When usingRemoteAuthProvider+JWTVerifierfor Managed Identity deployments, there was no way to configure scopes that work for both token validation and OAuth metadata —required_scopesserves both purposes.This adds
AzureJWTVerifier, aJWTVerifiersubclass that auto-configures JWKS, issuer, and audience fromclient_id/tenant_id, and bridges the scope format gap automatically. Users write scope names as they appear in Azure Portal:The verifier validates against short-form scopes (matching token
scpclaims) while advertising full URIs (api://client-id/access_as_user) in OAuth metadata.The plumbing:
TokenVerifiergains ascopes_supportedproperty (defaults torequired_scopes) thatRemoteAuthProvideruses for metadata.AzureJWTVerifieroverrides it to return prefixed scopes.RemoteAuthProvideralso accepts an explicitscopes_supportedparameter for non-Azure cases with the same pattern.Closes #3002
Note: implements #3002's option 3, which takes a more straightforward approach than proposed in options 1 and 2, at the expense of broader generality, as users would have to understand the implementation details in order to use the dual-kwargs. If there is demand for more general versions we can revisit!