feat(microsoft): add delegated oauth_token authentication#706
feat(microsoft): add delegated oauth_token authentication#706ds-filipknefel merged 3 commits intomainfrom
Conversation
Mirror the Google Drive oauth_token pattern across the three Microsoft Graph connectors (SharePoint, OneDrive, Outlook). - Add Optional `oauth_token` to OnedriveAccessConfig and OutlookAccessConfig (SharepointAccessConfig inherits from OnedriveAccessConfig). - Make `client_cred` / `client_credential` and `client_id` Optional so a delegated user access token can be supplied without app credentials. - model_post_init validators enforce at-least-one auth method and mutual exclusion of oauth_token with client_cred / password. - get_token / _acquire_token short-circuit on oauth_token: hand the bearer token through directly, no MSAL round-trip. Existing app-only and password-grant paths are unchanged. - Schema-validation unit tests for each AccessConfig variant. - Bump to 1.5.2; CHANGELOG entry added. Tokens typically expire after ~1 hour; refresh handling is out of scope for this connector.
|
@claude please review |
|
Claude finished @potter-potter's task —— View job Code Review: Microsoft OAuth Token AuthenticationI've completed my review of this PR that adds delegated OAuth token authentication to Microsoft Graph connectors. Overall, this is a well-implemented feature that follows good patterns. Todo List:
✅ StrengthsAuthentication Architecture
Implementation Quality
Code Safety
🔍 Minor Issues & SuggestionsField Naming Inconsistency (
|
Three corrections to the delegated oauth_token feature, all flagged on the initial review. - Cross-field validator on OneDrive/Outlook ConnectionConfig: require client_id when oauth_token is absent. Was previously caught only by a cryptic AADSTS / MSAL error at runtime. - model_post_init checks switched from "is not None" to truthiness so empty-string env vars no longer desync the validator from the runtime auth-mode branching in get_token / _acquire_token. - OAuth-mode advisory moved out of the per-Graph-request callback into a helper called from each Indexer/Uploader/Downloader precheck. Cuts log volume from one warning per request to one per pipeline step. SharePoint inherits from OneDrive so the validator and helper propagate; precheck override calls the helper explicitly. Six new unit tests pin the new behaviors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7fb41d4. Configure here.
| if access_config.oauth_token: | ||
| # Delegated user authentication: hand the access token through directly. | ||
| # Tokens typically expire after ~1 hour; refresh is not handled here. | ||
| return {"access_token": access_config.oauth_token, "token_type": "Bearer"} |
There was a problem hiding this comment.
oauth_token path unnecessarily requires msal dependency
Low Severity
The oauth_token short-circuit in get_token and _acquire_token is placed after the from msal import ... (and from requests import ...) statements. Both the @requires_dependencies decorator and these local imports execute before the if access_config.oauth_token: check, meaning the oauth_token path — which never uses MSAL — still requires msal (and requests) to be installed and importable. This contradicts the stated intent of "no MSAL round-trip" for the delegated token path.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7fb41d4. Configure here.


Summary
Mirror the Google Drive
oauth_tokenpattern across the three Microsoft Graph connectors (SharePoint, OneDrive, Outlook).oauth_tokentoOnedriveAccessConfigandOutlookAccessConfig(SharepointAccessConfiginherits fromOnedriveAccessConfig).client_cred/client_credentialandclient_idbecome Optional so a delegated user access token can be supplied without app credentials.model_post_initvalidators enforce at-least-one auth method and mutual exclusion ofoauth_tokenwithclient_cred/password.get_token/_acquire_tokenshort-circuit onoauth_token: hand the bearer token through directly, no MSAL round-trip. Existing app-only and password-grant paths are unchanged.Tokens typically expire after ~1 hour; refresh handling is out of scope for this connector — same model as the Google Drive
oauth_tokenfield.Test plan
Note
Medium Risk
Touches Microsoft Graph authentication/config validation for OneDrive/SharePoint/Outlook; misconfiguration could break existing credential-based flows, though changes are gated by new validation and the prior MSAL paths remain.
Overview
Adds delegated OAuth support to the Microsoft Graph connectors by introducing an optional
oauth_tokenon OneDrive/SharePoint/Outlook access configs and allowingclient_id/client_credto be omitted when a user access token is supplied.Implements stricter Pydantic validation (mutual exclusion and “at least one auth method”) plus a cross-field rule requiring
client_idwhenoauth_tokenis not set, and logs a one-time warning duringprecheckwhen token-based auth is used.Includes new unit tests covering these auth/validation combinations, and bumps the package to
1.5.2with a CHANGELOG entry.Reviewed by Cursor Bugbot for commit 7fb41d4. Bugbot is set up for automated code reviews on this repo. Configure here.