apolloconfig/apollo · error · BadRequestException

Unsupported auth type: %s

Error message

Unsupported auth type: %s

What it means

Thrown by AppController.resolveOperator when UserIdentityContextHolder.getAuthType() returns a value that is not USER, USER_TOKEN, or CONSUMER. This is a defensive guard indicating an unrecognized or null authentication type in the request context. It should not occur in normal operation — it signals a misconfiguration or a code path that bypasses the standard auth filter. Results in HTTP 400.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java:285

        || UserIdentityConstants.USER_TOKEN.equals(authType)) {
      UserInfo loginUser = userInfoHolder.getUser();
      if (loginUser == null || !StringUtils.hasText(loginUser.getUserId())) {
        throw new BadRequestException("Current user not found");
      }
      return loginUser.getUserId();
    }

    if (UserIdentityConstants.CONSUMER.equals(authType)) {
      if (!StringUtils.hasText(operator)) {
        throw new BadRequestException("operator should not be null or empty");
      }
      if (userService.findByUserId(operator) == null) {
        throw BadRequestException.userNotExists(operator);
      }
      return operator;
    }

    throw new BadRequestException("Unsupported auth type: %s", authType);
  }

  private void validatePortalApp(OpenAppDTO app) {
    if (!UserIdentityConstants.USER.equals(UserIdentityContextHolder.getAuthType())) {
      return;
    }
    if (!StringUtils.hasText(app.getName())) {
      throw BadRequestException.appNameIsBlank();
    }
    if (!InputValidator.isValidClusterNamespace(app.getAppId())) {
      throw new BadRequestException("Invalid AppId format: %s",
          InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE);
    }
    if (!StringUtils.hasText(app.getOrgId())) {
      throw BadRequestException.orgIdIsBlank();
    }
    if (!StringUtils.hasText(app.getOrgName())) {
      throw new BadRequestException("orgName can not be blank");

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Verify the authentication interceptor/filter sets UserIdentityContextHolder with one of the recognized constants (USER, USER_TOKEN, CONSUMER) before the controller executes.
  2. If a new auth type was added, extend resolveOperator to handle it.
  3. For unit tests, set UserIdentityContextHolder.setAuthType(UserIdentityConstants.CONSUMER) before calling the controller.
Defensive patterns

Strategy: validation

Validate before calling

// Verify the auth type is recognized before calling controller methods
String authType = UserIdentityContextHolder.getAuthType();
if (!UserIdentityConstants.USER.equals(authType)
    && !UserIdentityConstants.USER_TOKEN.equals(authType)
    && !UserIdentityConstants.CONSUMER.equals(authType)) {
    throw new IllegalStateException(
        "Unrecognized or missing auth type: " + authType + ". Check the auth filter configuration.");
}

Type guard

public static boolean isRecognizedAuthType(String authType) {
    return UserIdentityConstants.USER.equals(authType)
        || UserIdentityConstants.USER_TOKEN.equals(authType)
        || UserIdentityConstants.CONSUMER.equals(authType);
}

Prevention

When it happens

Trigger: A request reaches a controller method that calls resolveOperator, but the auth filter did not set any auth type, or set an unexpected value in UserIdentityContextHolder. This can happen if a new endpoint is exposed without the auth filter, or if a custom auth mechanism sets an unrecognized type.

Common situations: A new auth type was introduced in the codebase but resolveOperator was not updated to handle it. The UserIdentityContextHolder thread-local was cleared or never set due to a missing interceptor. A test calls the controller directly without setting up the auth context.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/cfff94b55158adb2. Report an issue: GitHub.