git-ecosystem/git-credential-manager · error · ArgumentException

Must specify at least one OAuthAuthenticationModes

Error message

Must specify at least one OAuthAuthenticationModes

What it means

GetAuthenticationModeAsync reduces the requested OAuthAuthenticationModes (after filtering out modes unavailable in the current environment) and throws ArgumentException if nothing remains. The library cannot perform OAuth without at least one usable authentication mode.

Solutions

  1. Pass a non-zero combination of OAuthAuthenticationModes (Browser and/or DeviceCode)
  2. Enable at least one mode in settings when environment filtering removes the others
  3. Allow DeviceCode as a fallback for headless environments
  4. Check upstream option parsing so OAuthAuthenticationModes.None is never passed

Example fix

// before
var mode = await oauth.GetAuthenticationModeAsync(OAuthAuthenticationModes.None, ...);
// after
var mode = await oauth.GetAuthenticationModeAsync(
    OAuthAuthenticationModes.Browser | OAuthAuthenticationModes.DeviceCode, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (modes == OAuthAuthenticationModes.None) throw new ArgumentException("At least one OAuthAuthenticationModes flag must be set.", nameof(modes));

Type guard

bool HasUsableMode(OAuthAuthenticationModes m) => (m & OAuthAuthenticationModes.Browser) != 0 || (m & OAuthAuthenticationModes.DeviceCode) != 0;

Try / catch

try { mode = await oauth.GetAuthenticationModeAsync(modes, ...); } catch (ArgumentException) { mode = OAuthAuthenticationModes.DeviceCode; }

Prevention

When it happens

Trigger: Calling GetAuthenticationModeAsync with modes = OAuthAuthenticationModes.None, or with a combination that is entirely filtered out (e.g. Browser removed because there is no desktop session and DeviceCode disabled).

Common situations: Configuring GCM with all auth modes disabled via settings (e.g. GCM_CREDENTIAL_* flags); running headless where browser mode is unavailable while device code is also excluded; passing a zero-value enum by mistake.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/6fd42ef3575f4299. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/Authentication/OAuthAuthentication.cs:55

            : base (context) { }

        public async Task<OAuthAuthenticationModes> GetAuthenticationModeAsync(
            string resource, OAuthAuthenticationModes modes)
        {
            EnsureArgument.NotNullOrWhiteSpace(resource, nameof(resource));

            ThrowIfUserInteractionDisabled();

            // Browser requires a desktop session!
            if (!Context.SessionManager.IsDesktopSession)
            {
                modes &= ~OAuthAuthenticationModes.Browser;
            }

            // We need at least one mode!
            if (modes == OAuthAuthenticationModes.None)
            {
                throw new ArgumentException(@$"Must specify at least one {nameof(OAuthAuthenticationModes)}", nameof(modes));
            }

            // If there is no mode choice to be made then just return that result
            if (modes == OAuthAuthenticationModes.Browser ||
                modes == OAuthAuthenticationModes.DeviceCode)
            {
                return modes;
            }

            if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession)
            {
                if (TryFindHelperCommand(out string command, out string args))
                {
                    return await GetAuthenticationModeViaHelperAsync(resource, modes, args, command);
                }

                return await GetAuthenticationModeViaUiAsync(resource, modes);
            }

View on GitHub (pinned to e8ce762cd0)