languagetool-org/languagetool · error · IllegalArgumentException
Unknown authMethod
Error message
Unknown authMethod: <authParameter>
What it means
The optional 'authMethod' query parameter of /v2/users/me must be one of 'password', 'apiKey', or 'addonToken'; any other value makes handleGetUserInfoRequest throw an IllegalArgumentException listing the offending value. It tells the server how to interpret the password part of the Basic auth credentials.
Solutions
- Set authMethod to one of exactly: password, apiKey, addonToken (case-sensitive).
- Omit the authMethod parameter entirely to use the default 'password'.
- Fix casing: 'apiKey' with a capital K, not 'apikey' or 'api_key'.
Example fix
// before GET /v2/users/me?authMethod=apikey // after GET /v2/users/me?authMethod=apiKey
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = ['password', 'apiKey', 'addonToken'];
if (authMethod && !ALLOWED.includes(authMethod)) throw new Error(`authMethod must be one of ${ALLOWED.join(', ')}`); Type guard
function isValidAuthMethod(v) {
return v === undefined || ['password', 'apiKey', 'addonToken'].includes(v);
} Prevention
- Keep an allowlist of valid authMethod values ('password', 'apiKey', 'addonToken') in client code.
- Omit authMethod to get the 'password' default.
- Match casing exactly when upgrading client libraries.
When it happens
Trigger: GET /v2/users/me?authMethod=oauth (unsupported value); typo like 'apikey' vs 'apiKey'; client library emitting an auth method this server version does not know.
Common situations: Newer/older client-server version mismatches where one side supports an auth method the other doesn't; hand-written query strings with wrong casing.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Expected Basic Authentication
- 'lang' parameter missing
- Missing 'text' or 'data' parameter
- 'ruleId' parameter missing
- apiKey AND password was set, set only apiKey
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/8212735f01d0c419.
Report an issue: GitHub.
Appendix: source
Thrown at languagetool-server/src/main/java/org/languagetool/server/ApiV2.java:366
if (httpExchange.getRequestMethod().equalsIgnoreCase("options")) {
ServerTools.setAllowOrigin(httpExchange, allowOriginUrl);
httpExchange.getResponseHeaders().put("Access-Control-Allow-Methods", Collections.singletonList("GET, OPTIONS"));
List<String> requestHeaders = httpExchange.getRequestHeaders().get("Access-Control-Request-Headers");
if (requestHeaders != null) {
httpExchange.getResponseHeaders().put("Access-Control-Allow-Headers", Collections.singletonList(String.join(", ", requestHeaders)));
}
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_NO_CONTENT, -1);
ServerMetricsCollector.getInstance().logResponse(HttpURLConnection.HTTP_NO_CONTENT);
} else {
ensureGetMethod(httpExchange, "/users/me");
if (!httpExchange.getRequestHeaders().containsKey("Authorization")) {
throw new AuthException("Expected Basic Authentication");
}
String authParameter = parameters.getOrDefault("authMethod", "password");
if (!(authParameter.equals("password") ||
authParameter.equals("apiKey") ||
authParameter.equals("addonToken"))) {
throw new IllegalArgumentException("Unknown authMethod: " + authParameter);
}
String authHeader = httpExchange.getRequestHeaders().getFirst("Authorization");
BasicAuthentication basicAuthentication = new BasicAuthentication(authHeader);
String user = basicAuthentication.getUser();
String password = basicAuthentication.getPassword();
UserInfoEntry userInfo = null;
if (authParameter.equals("password")) {
userInfo = DatabaseAccess.getInstance().getUserInfoWithPassword(user, password);
} else if (authParameter.equals("addonToken")) {
userInfo = DatabaseAccess.getInstance().getUserInfoWithAddonToken(user, password);
} else if (authParameter.equals("apiKey")) {
userInfo = DatabaseAccess.getInstance().getUserInfoWithApiKey(user, password);
}
String format = parameters.getOrDefault("format", "extended");
if (userInfo != null) {View on GitHub (pinned to 2e990059ce)