spring-projects/spring-security · error · IllegalArgumentException
No enum constant org.springframework.security.oauth2.client.
Error message
No enum constant org.springframework.security.oauth2.client.registration.CommonOAuth2Provider.{value} What it means
ClientRegistrationsBeanDefinitionParser resolves a common OAuth2 provider name to the CommonOAuth2Provider enum using case-insensitive canonical-name matching. If the configured registration id does not match any enum constant, it throws IllegalArgumentException listing the missing enum name.
Source
Thrown at config/src/main/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParser.java:249
}
catch (Exception ex) {
return findEnum(value);
}
}
catch (Exception ex) {
return null;
}
}
private static CommonOAuth2Provider findEnum(String value) {
String name = getCanonicalName(value);
for (CommonOAuth2Provider candidate : EnumSet.allOf(CommonOAuth2Provider.class)) {
String candidateName = getCanonicalName(candidate.name());
if (name.equals(candidateName)) {
return candidate;
}
}
throw new IllegalArgumentException(
"No enum constant " + CommonOAuth2Provider.class.getCanonicalName() + "." + value);
}
private static String getCanonicalName(String name) {
StringBuilder canonicalName = new StringBuilder(name.length());
name.chars()
.filter(Character::isLetterOrDigit)
.map(Character::toLowerCase)
.forEach((c) -> canonicalName.append((char) c));
return canonicalName.toString();
}
private static String getErrorMessage(String configuredProviderId, String registrationId) {
return (configuredProviderId != null) ? "Unknown provider ID '" + configuredProviderId + "'"
: "Provider ID must be specified for client registration '" + registrationId + "'";
}
}View on GitHub (pinned to 96852e8860)
Solutions
- Use one of the supported CommonOAuth2Provider values: google, github, facebook, okta (case/underscores normalized)
- Check spelling of the provider value in the XML configuration
- For providers not in CommonOAuth2Provider, define the ClientRegistration manually (builder or properties file) instead of the common-provider shorthand
Example fix
// before <oauth2-client:client-registrations> <oauth2-client:client-registration registration-id="gogle" client-id="abc" client-secret="xyz"/> </oauth2-client:client-registrations> // after <oauth2-client:client-registrations> <oauth2-client:client-registration registration-id="google" client-id="abc" client-secret="xyz"/> </oauth2-client:client-registrations>
Defensive patterns
Strategy: validation
Validate before calling
boolean valid;
try {
CommonOAuth2Provider.valueOf(value.toUpperCase());
valid = true;
} catch (IllegalArgumentException e) {
valid = false;
}
if (!valid) throw new IllegalArgumentException(value + " is not a CommonOAuth2Provider (google, github, facebook, okta)"); Try / catch
try {
ClientRegistrations.fromIssuerLocation(issuer);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("No enum constant")) {
// fall back to a manual ClientRegistration builder
}
} Prevention
- Only use provider ids supported by CommonOAuth2Provider in XML shorthand
- For other providers, use spring.security.oauth2.client.registration.* properties or a manual builder
- Validate provider names at startup with a unit test
When it happens
Trigger: In Spring XML OAuth2 client configuration (<client-registrations>) specifying a provider value that is not one of CommonOAuth2Provider's constants (e.g. a typo like 'gogle' or an unsupported provider like 'linkedin').
Common situations: Migrating properties-based OAuth2 config to XML; using a provider name valid in Spring Boot's properties but not in CommonOAuth2Provider; misspelling GOOGLE, GITHUB, FACEBOOK, or OKTA.
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
- missing_user_info_uri
- missing_user_name_attribute
- missing_user_info_uri
- missing_user_name_attribute
- Invalid Client Registration with Id: ${registrationId}
AI-assisted analysis of spring-projects/spring-security@96852e8860 (2026-09-10).
Data as JSON: /api/errors/41a46a3928accd8f.
Report an issue: GitHub.