fix: per-tenant AuthenticationRecord + InteractiveBrowserCredential in auth.py#46
Open
suyask-msft wants to merge 1 commit into
Open
fix: per-tenant AuthenticationRecord + InteractiveBrowserCredential in auth.py#46suyask-msft wants to merge 1 commit into
suyask-msft wants to merge 1 commit into
Conversation
…n auth.py Two related auth.py fixes for the developer-box flow, combined because they touch overlapping code paths. 1. Per-tenant AuthenticationRecord (cross-tenant bug fix) Previously auth.py stored the AuthenticationRecord at a single global path (dataverse_cli_auth_record.json). Because a record's home_account_id is tenant-bound, switching tenants overwrote the file and forced a full re-auth on the next switch-back. Now the record path includes TENANT_ID: dataverse_cli_auth_record_<tenant_id>.json Existing users are handled gracefully: _read_auth_record() falls back to the legacy global path on first run; the next successful auth writes to the new per-tenant path. Same-tenant multi-env behavior is unchanged (MSAL's internal cache already holds multiple resource-scope access tokens). 2. InteractiveBrowserCredential instead of DeviceCodeCredential The dv-connect flow already uses interactive browser auth for PAC CLI and the MCP proxy. auth.py was the outlier: it printed a URL and asked the user to type a code. That was the only manual-typing step in the whole flow. Switching to InteractiveBrowserCredential aligns auth.py with the rest of the stack, matches industry convention (Azure CLI, az login, gh auth login), and eliminates the code-typing UX. Token caching unchanged: same TokenCachePersistenceOptions, same AuthenticationRecord persistence (now per-tenant). No new env vars. Version: 1.2.0 -> 1.2.1 (PATCH) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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
Two related fixes to
scripts/auth.py, combined because they touch overlapping code paths.Changes
1. Per-tenant
AuthenticationRecord(cross-tenant bug fix)Previously
auth.pystored theAuthenticationRecordat a single global path (dataverse_cli_auth_record.json). Because a record'shome_account_idis tenant-bound, switching tenants overwrote the file and forced a full re-auth on the next switch-back — a popup loop for developers working across multiple tenants.Record path now includes
TENANT_ID:Smooth upgrade:
_read_auth_record()falls back to the legacy global path on first run, so existing users keep their cached record. The next successful auth writes to the new per-tenant path. No user action required.Same-tenant multi-env unchanged: MSAL's internal cache already holds multiple resource-scope access tokens per (user + tenant), so same-tenant users see no change.
2.
InteractiveBrowserCredentialinstead ofDeviceCodeCredentialAligns
auth.pywith the rest of thedv-connectstack:pac auth create)@microsoft/dataverse mcp)auth.pyAfter this PR, all three stacks present a consistent browser-popup sign-in experience. No more typing codes.
Industry convention (Azure SDK docs, MSAL guidance) recommends interactive browser as the default for workstation CLIs; device code is documented as a fallback for headless/SSH contexts. This change brings
auth.pyin line with that norm.What stays the same
CLIENT_ID+CLIENT_SECRET) — unchanged, still highest priorityTokenCachePersistenceOptions— same cache name, same OS credential storeAuthenticationRecordpersistence semantics — saved on first successful auth, reused by subsequent processesVersion bump
1.2.0 → 1.2.1 (PATCH — cross-tenant bug fix + UX alignment, no breaking change)
Test plan
python -c "import ast; ast.parse(...)"— syntax validpython .github/evals/static_checks.py— passes (6 categories, 70 Python blocks)python .github/evals/version_bump_check.py— passesdv-connect, verifyauth.pyopens browser (not device code)Notes
The change to
InteractiveBrowserCredentialhas been discussed extensively in prior iterations (closed PR #45 explored this). The final call: align with the rest of the stack; don't introduce a device-code opt-in env var; in the rare cases where interactive browser fails (SSH / headless / WSL-no-forwarding), users can configure a service principal (the canonical non-interactive path Microsoft recommends).