justauth/JustAuth · error · AuthException
accessTokenObject.getString("error_description")
Error message
accessTokenObject.getString("error_description") What it means
AuthMiRequest.getToken throws AuthException with 'error_description' when the Xiaomi OAuth token response (after stripping the '&&&START&&&' prefix) contains an 'error' key. Xiaomi returns standard OAuth2 error descriptions for failed code exchanges.
Source
Thrown at src/main/java/me/zhyd/oauth/request/AuthMiRequest.java:51
super(config, AuthDefaultSource.MI);
}
public AuthMiRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthDefaultSource.MI, authStateCache);
}
@Override
public AuthToken getAccessToken(AuthCallback authCallback) {
return getToken(accessTokenUrl(authCallback.getCode()));
}
private AuthToken getToken(String accessTokenUrl) {
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
String jsonStr = response.replace(PREFIX, Constants.EMPTY);
JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);
if (accessTokenObject.containsKey("error")) {
throw new AuthException(accessTokenObject.getString("error_description"));
}
return AuthToken.builder()
.accessToken(accessTokenObject.getString("access_token"))
.expireIn(accessTokenObject.getIntValue("expires_in"))
.scope(accessTokenObject.getString("scope"))
.tokenType(accessTokenObject.getString("token_type"))
.refreshToken(accessTokenObject.getString("refresh_token"))
.openId(accessTokenObject.getString("openId"))
.macAlgorithm(accessTokenObject.getString("mac_algorithm"))
.macKey(accessTokenObject.getString("mac_key"))
.build();
}
@Override
public AuthUser getUserInfo(AuthToken authToken) {
// 获取用户信息
String userResponse = doGetUserInfo(authToken);View on GitHub (pinned to 694bbf1b01)
Solutions
- Log error_description from the AuthException — Xiaomi states the exact failure
- Verify clientId/clientSecret/redirectUri against the Xiaomi developer console
- Restart the OAuth flow to get a fresh code rather than retrying the same callback
- Confirm the app's package name/signature binding if the flow originated from a mobile client
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try {
miRequest.getAuthResponse(callback);
} catch (AuthException e) {
log.warn("Xiaomi token error: {}", e.getMessage());
return redirectToLogin();
} Prevention
- Confirm Xiaomi developer console credentials and redirect URI
- Exchange codes promptly — Xiaomi grant codes expire quickly
- Log error_description; it distinguishes credential vs grant failures
When it happens
Trigger: Calling getAccessToken or refresh on AuthMiRequest when Xiaomi's account API rejects the grant: invalid code, wrong client secret, redirect mismatch, or missing scope.
Common situations: Xiaomi developer credentials misconfigured, authorization code older than its short TTL, or the app not published/approved on Xiaomi's developer console.
Related errors
- object.getString("sub_error") + ":" + object.getString("erro
- userProfile.getString("description")
- object.getString("error_description")
- object.getString("error_description") / object.getString("er
- object.getString("msg")
AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14).
Data as JSON: /api/errors/a9dba3949463ff43.
Report an issue: GitHub.