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
- Pass a non-zero combination of OAuthAuthenticationModes (Browser and/or DeviceCode)
- Enable at least one mode in settings when environment filtering removes the others
- Allow DeviceCode as a fallback for headless environments
- 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
- Always pass at least Browser|DeviceCode
- Enable device code as a fallback in headless environments
- Audit GCM settings that disable auth modes before requesting credentials
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.
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- No authentication mode selected!
- Failed to resolve username. HTTP
- Bitbucket DC OAuth Client ID must be defined
- Bitbucket DC OAuth Client Secret must be defined
- RemoteUri must be defined to generate Bitbucket DC OAuth2…
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)