dromara/Sa-Token · error · SaOAuth2ClientModelException

30105

30105

Error message

无效 client_id: 

What it means

Thrown by SaOAuth2DataLoader.getClientModelNotNull when getClientModel(clientId) returns null — no SaClientModel is registered for that client_id in the server config. Code 30105 marks an invalid client_id; the exception carries the clientId.

Source

Thrown at sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/data/loader/SaOAuth2DataLoader.java:54

     *
     * @param clientId 应用id
     * @return ClientModel
     */
    default SaClientModel getClientModel(String clientId) {
        // 默认从内存配置中读取数据
        return SaOAuth2Manager.getServerConfig().getClients().get(clientId);
    }

    /**
     * 根据 id 获取 Client 信息,不允许为 null
     *
     * @param clientId 应用id
     * @return ClientModel
     */
    default SaClientModel getClientModelNotNull(String clientId) {
        SaClientModel clientModel = getClientModel(clientId);
        if(clientModel == null) {
            throw new SaOAuth2ClientModelException("无效 client_id: " + clientId)
                    .setClientId(clientId)
                    .setCode(SaOAuth2ErrorCode.CODE_30105);
        }
        return clientModel;
    }

    /**
     * 根据 ClientId 和 LoginId 获取 openid
     *
     * @param clientId 应用id
     * @param loginId 账号id
     * @return 此账号在此Client下的openid
     */
    default String getOpenid(String clientId, Object loginId) {
        return SaSecureUtil.md5(SaOAuth2Manager.getServerConfig().getOpenidDigestPrefix() + "_" + clientId + "_" + loginId);
    }

    /**

View on GitHub (pinned to ac2c7f6e94)

Solutions

  1. Add (or fix) the client entry under sa-token.oauth2-server.clients with the exact client-id the client sends
  2. Verify the client application's configured client_id matches char-for-char (case-sensitive)
  3. If you implement SaOAuth2DataLoader yourself, make getClientModel return a model for every valid client id

Example fix

# before
sa-token:
  oauth2-server:
    clients:
      - client-id: my-web   # client sends "my-app" -> 30105

# after
sa-token:
  oauth2-server:
    clients:
      - client-id: my-app
        client-secret: xxx
        ...
Defensive patterns

Strategy: validation

Validate before calling

SaClientModel cm = saOAuth2DataLoader.getClientModel(clientId);
if (cm == null) {
    return badRequest("unknown client_id: " + clientId);
}

Try / catch

catch (SaOAuth2ClientModelException e) { if (e.getCode() == SaOAuth2ErrorCode.CODE_30105) { /* 400 invalid_client */ } }

Prevention

When it happens

Trigger: Any OAuth2 endpoint (authorize, token) receiving a client_id that is not a key of sa-token.oauth2-server.clients in the configuration, or a custom SaOAuth2DataLoader implementation returning null for that id.

Common situations: client_id typo in the client application; the client was registered in a different environment's config; the 'clients' block is missing/malformed (wrong indentation) so no clients load at all; custom data loader forgets to handle a new client.

Related errors


AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14). Data as JSON: /api/errors/ce92d96b498ccddf. Report an issue: GitHub.