{"record":{"id":"b85866f456b18094","repo":"git-ecosystem/git-credential-manager","slug":"unknown-oauth2-response-mode","errorCode":null,"errorMessage":"Unknown OAuth2 response mode.","messagePattern":"Unknown OAuth2 response mode\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/Authentication/OAuth/OAuth2ResponseMode.cs","lineNumber":52,"sourceCode":"public static class OAuth2ResponseModeExtensions\n{\n    /// <summary>\n    /// Get the wire value for the <c>response_mode</c> authorization request parameter.\n    /// </summary>\n    public static string GetParameterValue(this OAuth2ResponseMode mode)\n    {\n        switch (mode)\n        {\n            case OAuth2ResponseMode.Default:\n                return null;\n            case OAuth2ResponseMode.Query:\n                return OAuth2Constants.AuthorizationEndpoint.QueryResponseMode;\n            case OAuth2ResponseMode.Fragment:\n                return OAuth2Constants.AuthorizationEndpoint.FragmentResponseMode;\n            case OAuth2ResponseMode.FormPost:\n                return OAuth2Constants.AuthorizationEndpoint.FormPostResponseMode;\n            default:\n                throw new ArgumentOutOfRangeException(nameof(mode), mode, \"Unknown OAuth2 response mode.\");\n        }\n    }\n\n    /// <summary>\n    /// Try to parse a <c>response_mode</c> wire value into an <see cref=\"OAuth2ResponseMode\"/>.\n    /// </summary>\n    public static bool TryParse(string value, out OAuth2ResponseMode mode)\n    {\n        mode = OAuth2ResponseMode.Default;\n\n        if (string.IsNullOrWhiteSpace(value))\n        {\n            return false;\n        }\n\n        if (StringComparer.OrdinalIgnoreCase.Equals(value, OAuth2Constants.AuthorizationEndpoint.QueryResponseMode))\n        {\n            mode = OAuth2ResponseMode.Query;","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Authentication/OAuth/OAuth2ResponseMode.cs#L34-L70","documentation":"OAuth2ResponseMode.GetParameterValue maps the OAuth2ResponseMode enum to its wire value ('query', 'fragment', 'form_post'). An ArgumentOutOfRangeException is thrown for any mode value outside those three, because no corresponding response_mode string exists.","triggerScenarios":"Calling GetParameterValue on an OAuth2ResponseMode value not covered by the switch — typically an undefined enum value obtained via an unchecked cast, default initialization, or a value parsed from untrusted input.","commonSituations":"Deserializing 'response_mode' from an authorization response into the enum without validating; enum default (0) not mapping to a defined mode; adding a new response mode upstream without updating this mapper.","solutions":["Pass only OAuth2ResponseMode.Query, .Fragment, or .FormPost to GetParameterValue","Use TryParseResponseMode (the parsing helper in the same file) instead of manual casts","Validate the enum value before mapping; treat unexpected values as a configuration error","Check that the enum was not default-initialized to a value with no wire representation"],"exampleFix":"// before\nvar value = OAuth2ResponseModeExtensions.GetParameterValue((OAuth2ResponseMode)7);\n// after\nif (OAuth2ResponseModeExtensions.TryParseResponseMode(\"query\", out var mode))\n{\n    var value = OAuth2ResponseModeExtensions.GetParameterValue(mode);\n}","handlingStrategy":"validation","validationCode":"if (mode is not (OAuth2ResponseMode.Query or OAuth2ResponseMode.Fragment or OAuth2ResponseMode.FormPost)) throw new ArgumentException($\"Unsupported response mode: {mode}\");","typeGuard":"bool IsKnownResponseMode(OAuth2ResponseMode m) => m == OAuth2ResponseMode.Query || m == OAuth2ResponseMode.Fragment || m == OAuth2ResponseMode.FormPost;","tryCatchPattern":"try { value = OAuth2ResponseModeExtensions.GetParameterValue(mode); } catch (ArgumentOutOfRangeException) { value = OAuth2Constants.AuthorizationEndpoint.QueryResponseMode; }","preventionTips":["Prefer TryParseResponseMode over manual enum casts","Never rely on enum default values; initialize modes explicitly","Map wire strings to enum only via the library's parse helpers"],"tags":["oauth2","response-mode","argumentoutofrange","enum"],"backgroundTag":"invalid-enum-value","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"}