Fix macOS Keychain support and M365 scope consistency - #73
Open
arosenfeld2003 wants to merge 2 commits into
Open
Fix macOS Keychain support and M365 scope consistency#73arosenfeld2003 wants to merge 2 commits into
arosenfeld2003 wants to merge 2 commits into
Conversation
StorageCreationPropertiesBuilder special-cased Linux (unprotected file storage) but never called WithMacKeyChain() for macOS, so MSAL's cross-platform cache helper throws "Value cannot be null. (Parameter 'keyChainServiceName')" on first use on macOS despite the security docs claiming Keychain-backed storage is already implemented.
…ovider add-m365-account always requested the hardcoded M365Scopes.WithFiles set during interactive login, while M365ProviderService always requested the separate M365Scopes.Default set for silent token acquisition at runtime. For an app registration granted a narrower set of permissions (e.g. Calendars.Read only, for least-privilege setups), this mismatch makes every read call silently fail: AcquireTokenSilent can't upgrade scope without interactive consent, throws internally, and every provider method swallows the exception and returns an empty result with only a log warning - so calendar/email/contact queries just look like "no data" with no visible error. Now the CLI prompts for scopes (defaulting to the previous WithFiles set for backward compatibility) and persists the chosen set on the account's ProviderConfig. M365ProviderService reads that per-account Scopes value when present, falling back to the historical default for existing configs that don't have it set.
|
@rockfordlhotka appreciate any feedback on this - with these changes I’m set up successfully on mac os (with Claude). Thanks! |
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 found while setting up an M365 account on macOS with
a least-privilege (
Calendars.Read-only) app registration:macOS Keychain support was never wired up (fixes macOS: M365 token cache throws on first use (missing WithMacKeyChain) #70).
StorageCreationPropertiesBuilderspecial-cased Linux(
WithLinuxUnprotectedFile) but never calledWithMacKeyChain(...)for macOS, so MSAL's cache helper throws
Value cannot be null. (Parameter 'keyChainServiceName')on firstuse, despite
security.mddocumenting Keychain-backed storage asalready implemented.
add-m365-accountandM365ProviderServicerequested different,hardcoded scope sets (fixes M365: add-m365-account and provider silently request different, hardcoded scopes #71). The CLI always requested
M365Scopes.WithFilesat login; the provider always requested theseparate
M365Scopes.Defaultfor silent token acquisition atruntime. For any app registration granted a narrower permission set
than either hardcoded default, this mismatch causes every read call
to silently fail (
AcquireTokenSilentcan't upgrade scope withoutinteractive consent) and return an empty result with no visible
error — see M365 provider: all read methods swallow exceptions and return empty results #72 for the related silent-failure issue, not addressed
in this PR to keep the diff focused.
Changes
M365AuthenticationService.GetOrCreateAppAsync: add a macOS branchcalling
WithMacKeyChain(serviceName, accountName)alongside theexisting Linux branch.
AddM365AccountCommand: prompt for scopes (default: the previousWithFilesset, so existing behavior is unchanged if you accept thedefault), persist the chosen scopes to
ProviderConfig["Scopes"].M365ProviderService.GetAccessTokenAsync: readProviderConfig["Scopes"]per-account when present, falling back tothe historical
M365Scopes.Defaultfor accounts configured beforethis change (fully backward compatible).
OAuthScopes.cs: add aM365Scopes.CalendarsReadOnlyconvenienceconstant for the calendar-only case.
Testing
Built from source on macOS (arm64, net10.0). Verified end-to-end with
a real Entra app registration scoped to
Calendars.Readonly:registered the app, ran
add-m365-accountwith a custom (narrower)scope, authenticated interactively, and confirmed
get_calendar_events/
list_calendarsreturn real data via the MCP stdio server — prior tothis fix, both silently returned empty results due to the scope
mismatch in issue #71.
Also verified the default (no scopes entered, accept
WithFilesdefault) path still works unchanged, for backward compatibility with
existing configs that don't have a
Scopeskey.Closes #70, #71.