justauth/JustAuth · error · AuthException
userProfile.getString("description")
Error message
userProfile.getString("description") What it means
AuthMiRequest.getUserInfo throws AuthException with the 'description' field when the user-profile response has result=="error". This is Xiaomi's user-info envelope: {result: 'error'|'ok', description: ..., data: {...}}.
Source
Thrown at src/main/java/me/zhyd/oauth/request/AuthMiRequest.java:73
.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);
JSONObject userProfile = JSONObject.parseObject(userResponse);
if ("error".equalsIgnoreCase(userProfile.getString("result"))) {
throw new AuthException(userProfile.getString("description"));
}
JSONObject object = userProfile.getJSONObject("data");
AuthUser authUser = AuthUser.builder()
.rawUserInfo(object)
.uuid(authToken.getOpenId())
.username(object.getString("miliaoNick"))
.nickname(object.getString("miliaoNick"))
.avatar(object.getString("miliaoIcon"))
.email(object.getString("mail"))
.gender(AuthUserGender.UNKNOWN)
.token(authToken)
.source(source.toString())
.build();
// 获取用户邮箱手机号等信息
String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", configView on GitHub (pinned to 694bbf1b01)
Solutions
- Refresh the token (AuthMiRequest supports refresh_token) before fetching user info
- Track expiresIn and refresh proactively; do not call getUserInfo with stale tokens
- Read the 'description' message to distinguish expiry from permission errors
- Fall back to re-authorization when refresh also fails
Example fix
null
Defensive patterns
Strategy: retry
Validate before calling
boolean tokenFresh = System.currentTimeMillis() < token.getExpiresIn() * 1000L + issuedAtMs;
if (!tokenFresh) {
token = miRequest.refresh(token).getData();
} Type guard
null
Try / catch
try {
return miRequest.getUserInfo(token);
} catch (AuthException e) {
// 'description' says why; on token errors refresh once and retry
token = miRequest.refresh(token).getData();
return miRequest.getUserInfo(token);
} Prevention
- Store issuedAt + expiresIn and refresh before expiry
- Handle refresh failure by forcing re-authorization
- Request the profile permission scope in the Xiaomi console
When it happens
Trigger: Calling getUserInfo with an access token Xiaomi rejects (expired/revoked), or when the user profile API permission is not enabled for the app.
Common situations: Reusing a stored token beyond expires_in, token invalidated by user logout/password change, or missing profile-scope approval.
Related errors
- object.getString("m")
- accessTokenObject.getString("error_description")
- object.getString("msg")
- object.get("error") + ":" + object.get("error_description")
- object.getString("error_description") / object.getString("er
AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14).
Data as JSON: /api/errors/bda1962a25805eff.
Report an issue: GitHub.