-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Bug Description
a365 setup blueprint (standalone) fails to configure inheritable permissions for Microsoft Graph because graphApiService.CustomClientAppId is never set in the command handler. This causes Connect-MgGraph to omit the -ClientId parameter, falling back to the default Graph PowerShell SDK client app (14d82eec-204b-4c2f-b7e8-296a70dab67e), which lacks the required AgentIdentityBlueprint.UpdateAuthProperties.All permission.
Error Message
Failed to configure Microsoft Graph inheritable permissions: AADSTS65001:
The user or administrator has not consented to use the application with ID '14d82eec-204b-4c2f-b7e8-296a70dab67e'
named 'Microsoft Graph Command Line Tools'. Send an interactive authorization request for this user and resource.
Root Cause
In BlueprintSubcommand.cs, the SetHandler block does not set graphApiService.CustomClientAppId = setupConfig.ClientAppId before calling CreateBlueprintImplementationAsync. Every other command that uses the Graph API correctly sets this property:
| Command | Sets CustomClientAppId? |
Location |
|---|---|---|
a365 setup all |
Yes | AllSubcommand.cs line ~138 |
a365 setup permissions |
Yes | PermissionsSubcommand.cs lines ~84, ~162 |
a365 deploy |
Yes | DeployCommand.cs line ~224 |
a365 cleanup |
Yes | CleanupCommand.cs lines ~99, ~446 |
a365 setup blueprint |
No — missing | BlueprintSubcommand.cs SetHandler block |
Call chain when CustomClientAppId is null
BlueprintSubcommand.SetHandler→ does not setgraphApiService.CustomClientAppIdCreateBlueprintImplementationAsync→ passesgraphApiServicetoCompleteBlueprintConfigurationAsyncCompleteBlueprintConfigurationAsync→ callsEnsureAdminConsentAsyncEnsureAdminConsentAsync→ callsSetupHelpers.EnsureResourcePermissionsAsyncwithsetInheritablePermissions: trueEnsureResourcePermissionsAsync→ callsblueprintService.SetInheritablePermissionsAsyncwithrequiredScopes: ["AgentIdentityBlueprint.UpdateAuthProperties.All", "Application.ReadWrite.All"]AgentBlueprintService.SetInheritablePermissionsAsync→ calls_graphApiService.GraphGetAsync/GraphPatchAsyncGraphApiService.EnsureGraphHeadersAsync→ calls_tokenProvider.GetMgGraphAccessTokenAsync(tenantId, scopes, false, CustomClientAppId, ct)whereCustomClientAppIdis nullMicrosoftGraphTokenProvider(line ~200): omits-ClientIdfromConnect-MgGraphbecauseclientAppIdis null/empty:var clientIdParam = !string.IsNullOrWhiteSpace(clientAppId) ? $" -ClientId '{CommandStringHelper.EscapePowerShellString(clientAppId)}'" : ""; // ← empty when CustomClientAppId is null
Connect-MgGraphwithout-ClientId→ defaults to SDK app14d82eec-204b-4c2f-b7e8-296a70dab67e- That app lacks
AgentIdentityBlueprint.UpdateAuthProperties.All→ AADSTS65001 error
Why macOS/Linux Shows the Symptom More Frequently
The bug exists on all platforms, but the symptom manifests differently:
macOS/Linux (no WAM broker)
Connect-MgGraphwithout-ClientIdhas no WAM broker to fall back to- Uses browser-based interactive auth with the default SDK client app
- The default SDK app
14d82eec-204b-4c2f-b7e8-296a70dab67edoes not have the required beta permissionAgentIdentityBlueprint.UpdateAuthProperties.All - Result: Always fails on the inheritable permissions step
Windows (WAM broker available)
- WAM (Web Account Manager) broker can reuse cached tokens from earlier interactive authentication that happened earlier in the same CLI session (e.g., during blueprint creation)
- Those cached tokens were acquired using the correct custom client app (from
MsalBrowserCredentialinGetTokenFromGraphClient) - WAM can silently return a token for the same account, masking the missing
-ClientId - Result: Often works due to cached tokens, but can fail on fresh machines, after token expiry, or in CI/CD environments
Additional reproduction factor
a365 setup allis not affected — it correctly setsCustomClientAppIdat line 138 ofAllSubcommand.cs- The bug only manifests when running standalone
a365 setup blueprint - On a first-time setup via
a365 setup all, everything works. The bug appears when users re-run just the blueprint step (e.g., to fix endpoint issues or recreate a blueprint)
Steps to Reproduce
- Have a tenant with a custom client app registration that has
AgentIdentityBlueprint.UpdateAuthProperties.All(beta) permission consented - Have
a365.config.jsonconfigured with validclientAppIdandtenantId - Run
a365 setup blueprint --verbose(standalone, nota365 setup all) - Observe that inheritable permissions step fails with AADSTS65001
More reliably reproduced on macOS/Linux where WAM is not available.
Proposed Fix
Add one line in BlueprintSubcommand.cs SetHandler block, after loading the config and before calling CreateBlueprintImplementationAsync:
var setupConfig = await configService.LoadAsync(config.FullName);
// ADD THIS LINE - matches pattern used by AllSubcommand, PermissionsSubcommand, etc.
graphApiService.CustomClientAppId = setupConfig.ClientAppId;This is consistent with every other command handler in the codebase that uses graphApiService.
Environment
- CLI Version: 1.1.62-preview+35cd754bfe
- Platforms affected: All (macOS/Linux always fails; Windows intermittently masked by WAM)
- Reported on: macOS ARM64 (Apple Silicon)
Workaround
Users can work around this by running a365 setup all --skip-infrastructure instead of standalone a365 setup blueprint, since AllSubcommand correctly sets CustomClientAppId.