microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Support a configurable or platform-appropriate location for .mg\mg.graphoptions.json

Open
#3,749 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

Microsoft Graph PowerShell currently stores Graph SDK options at:

%USERPROFILE%\.mg\mg.graphoptions.json

The location is hard-coded in Microsoft.Graph.Authentication:

GraphDirectoryPath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
    ".mg");

GraphOptionsFilePath is then constructed beneath that directory.

Source references in tag v2.36.1:

  • src/Authentication/Authentication.Core/Constants.cs
  • src/Authentication/Authentication/Constants.cs
  • src/Authentication/Authentication/Common/GraphSessionInitializer.cs
  • src/Authentication/Authentication/Cmdlets/SetMgGraphOption.cs

This creates another tool-specific dot-directory directly under the user profile, with no documented environment variable or configuration setting for relocating it.

Environment

OS: Windows
Microsoft.Graph.Authentication: 2.36.1
Current path: %USERPROFILE%\.mg\mg.graphoptions.json

The file contains SDK configuration options such as:

DisableWAMForMSGraph
DisableLoginByWAM

No authentication-token relocation is being requested in this issue; the immediate request concerns configuration files such as mg.graphoptions.json.

Expected behavior

Provide a supported way to relocate Microsoft Graph PowerShell configuration.

Possible approaches:

  1. Add an environment variable such as MSGRAPH_CONFIG_DIR.
  2. Follow platform conventions by default:
    • Windows: %APPDATA%\Microsoft\GraphPowerShell
    • Linux/macOS: $XDG_CONFIG_HOME/microsoft-graph, falling back to ~/.config/microsoft-graph
  3. Preserve the existing .mg location for backward compatibility and migrate or fall back to it when appropriate.

Motivation

A configurable location would:

  • Avoid adding application-specific directories to the profile root.
  • Support enterprise-managed and portable PowerShell environments.
  • Improve separation between configuration, cache, authentication state, and user data.
  • Allow consistent backup and profile-management policies.
  • Better align with platform conventions and the XDG Base Directory specification.

Existing related issue

#747 — Consider moving graph cache from .graph to .cache/graph to match XDG specification remains open.

That issue addresses Graph cache placement. This request is narrower and complementary: it covers the hard-coded .mg configuration directory and mg.graphoptions.json.

Acceptance criteria

  • A documented setting or environment variable controls the Graph PowerShell configuration directory.
  • Get-MgGraphOption and Set-MgGraphOption use the configured location.
  • Existing .mg configurations continue working through migration or backward-compatible fallback.
  • Windows, Linux, and macOS path behavior is documented and tested.
  • Configuration and cache locations can be controlled independently.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Constants.cs and GraphSessionInitializer.cs to trace how GraphDirectoryPath and GraphOptionsFilePath are selected, then inspect SetMgGraphOption.cs and the related authentication constants. Use the acceptance criteria to define the supported configuration, backward compatibility, independent cache handling, cross-platform behavior, documentation, and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.