{"record":{"id":"6fd42ef3575f4299","repo":"git-ecosystem/git-credential-manager","slug":"must-specify-at-least-one-oauthauthenticationmodes","errorCode":null,"errorMessage":"Must specify at least one OAuthAuthenticationModes","messagePattern":"Must specify at least one OAuthAuthenticationModes","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Core/Authentication/OAuthAuthentication.cs","lineNumber":55,"sourceCode":"            : base (context) { }\n\n        public async Task<OAuthAuthenticationModes> GetAuthenticationModeAsync(\n            string resource, OAuthAuthenticationModes modes)\n        {\n            EnsureArgument.NotNullOrWhiteSpace(resource, nameof(resource));\n\n            ThrowIfUserInteractionDisabled();\n\n            // Browser requires a desktop session!\n            if (!Context.SessionManager.IsDesktopSession)\n            {\n                modes &= ~OAuthAuthenticationModes.Browser;\n            }\n\n            // We need at least one mode!\n            if (modes == OAuthAuthenticationModes.None)\n            {\n                throw new ArgumentException(@$\"Must specify at least one {nameof(OAuthAuthenticationModes)}\", nameof(modes));\n            }\n\n            // If there is no mode choice to be made then just return that result\n            if (modes == OAuthAuthenticationModes.Browser ||\n                modes == OAuthAuthenticationModes.DeviceCode)\n            {\n                return modes;\n            }\n\n            if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession)\n            {\n                if (TryFindHelperCommand(out string command, out string args))\n                {\n                    return await GetAuthenticationModeViaHelperAsync(resource, modes, args, command);\n                }\n\n                return await GetAuthenticationModeViaUiAsync(resource, modes);\n            }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Authentication/OAuthAuthentication.cs#L37-L73","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nvar mode = await oauth.GetAuthenticationModeAsync(OAuthAuthenticationModes.None, ...);\n// after\nvar mode = await oauth.GetAuthenticationModeAsync(\n    OAuthAuthenticationModes.Browser | OAuthAuthenticationModes.DeviceCode, ...);","handlingStrategy":"validation","validationCode":"if (modes == OAuthAuthenticationModes.None) throw new ArgumentException(\"At least one OAuthAuthenticationModes flag must be set.\", nameof(modes));","typeGuard":"bool HasUsableMode(OAuthAuthenticationModes m) => (m & OAuthAuthenticationModes.Browser) != 0 || (m & OAuthAuthenticationModes.DeviceCode) != 0;","tryCatchPattern":"try { mode = await oauth.GetAuthenticationModeAsync(modes, ...); } catch (ArgumentException) { mode = OAuthAuthenticationModes.DeviceCode; }","preventionTips":["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"],"tags":["oauth","authentication-mode","argument","configuration"],"backgroundTag":"missing-required-argument","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}