justauth/JustAuth · error · AuthException

object.getString("error_description")

Error message

object.getString("error_description")

What it means

AuthGiteeRequest.checkResponse() implements the standard OAuth2 error check: any 'error' key in a Gitee response triggers AuthException with the 'error_description' text. It fires on token acquisition, refresh, and user-info calls.

Source

Thrown at src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java:75

            .nickname(object.getString("name"))
            .company(object.getString("company"))
            .location(object.getString("address"))
            .email(object.getString("email"))
            .remark(object.getString("bio"))
            .gender(AuthUserGender.UNKNOWN)
            .token(authToken)
            .source(source.toString())
            .build();
    }

    /**
     * 检查响应内容是否正确
     *
     * @param object 请求响应内容
     */
    private void checkResponse(JSONObject object) {
        if (object.containsKey("error")) {
            throw new AuthException(object.getString("error_description"));
        }
    }

    /**
     * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
     *
     * @param state state 验证授权流程的参数,可以防止csrf
     * @return 返回授权地址
     */
    @Override
    public String authorize(String state) {
        return UrlBuilder.fromBaseUrl(super.authorize(state))
            .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthGiteeScope.values())))
            .build();
    }
}

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Align client_id/client_secret with the Gitee application settings and re-save config.
  2. Make redirect_uri in AuthConfig match the Gitee app's callback address exactly.
  3. Call refresh() with the stored refresh_token when error_description mentions an invalid token.
  4. Consume each code once and handle duplicate callbacks idempotently.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return giteeRequest.getUserInfo(token);
} catch (AuthException e) {
    if (String.valueOf(e.getErrorMsg()).contains("token") || String.valueOf(e.getErrorMsg()).contains("grant")) {
        return giteeRequest.refresh(AuthToken.builder().refreshToken(refreshToken).build());
    }
    throw e;
}

Prevention

When it happens

Trigger: getAccessToken()/refresh()/getUserInfo() with incorrect client credentials, a reused authorization code, or a revoked/expired access token - Gitee answers {"error":"...","error_description":"..."}.

Common situations: Gitee OAuth app secret regenerated without updating config; redirect_uri with mismatched case or trailing slash compared to the app settings; access token past its 1-day validity with no refresh flow.

Related errors


AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14). Data as JSON: /api/errors/70f6ee847c5de13e. Report an issue: GitHub.