{"record":{"id":"bda1962a25805eff","repo":"justauth/JustAuth","slug":"userprofile-getstring-description","errorCode":null,"errorMessage":"userProfile.getString(\"description\")","messagePattern":"userProfile\\.getString\\(\"description\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthMiRequest.java","lineNumber":73,"sourceCode":"            .accessToken(accessTokenObject.getString(\"access_token\"))\n            .expireIn(accessTokenObject.getIntValue(\"expires_in\"))\n            .scope(accessTokenObject.getString(\"scope\"))\n            .tokenType(accessTokenObject.getString(\"token_type\"))\n            .refreshToken(accessTokenObject.getString(\"refresh_token\"))\n            .openId(accessTokenObject.getString(\"openId\"))\n            .macAlgorithm(accessTokenObject.getString(\"mac_algorithm\"))\n            .macKey(accessTokenObject.getString(\"mac_key\"))\n            .build();\n    }\n\n    @Override\n    public AuthUser getUserInfo(AuthToken authToken) {\n        // 获取用户信息\n        String userResponse = doGetUserInfo(authToken);\n\n        JSONObject userProfile = JSONObject.parseObject(userResponse);\n        if (\"error\".equalsIgnoreCase(userProfile.getString(\"result\"))) {\n            throw new AuthException(userProfile.getString(\"description\"));\n        }\n\n        JSONObject object = userProfile.getJSONObject(\"data\");\n\n        AuthUser authUser = AuthUser.builder()\n            .rawUserInfo(object)\n            .uuid(authToken.getOpenId())\n            .username(object.getString(\"miliaoNick\"))\n            .nickname(object.getString(\"miliaoNick\"))\n            .avatar(object.getString(\"miliaoIcon\"))\n            .email(object.getString(\"mail\"))\n            .gender(AuthUserGender.UNKNOWN)\n            .token(authToken)\n            .source(source.toString())\n            .build();\n\n        // 获取用户邮箱手机号等信息\n        String emailPhoneUrl = MessageFormat.format(\"{0}?clientId={1}&token={2}\", \"https://open.account.xiaomi.com/user/phoneAndEmail\", config","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java#L55-L91","documentation":"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: {...}}.","triggerScenarios":"Calling getUserInfo with an access token Xiaomi rejects (expired/revoked), or when the user profile API permission is not enabled for the app.","commonSituations":"Reusing a stored token beyond expires_in, token invalidated by user logout/password change, or missing profile-scope approval.","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"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"boolean tokenFresh = System.currentTimeMillis() < token.getExpiresIn() * 1000L + issuedAtMs;\nif (!tokenFresh) {\n    token = miRequest.refresh(token).getData();\n}","typeGuard":"null","tryCatchPattern":"try {\n    return miRequest.getUserInfo(token);\n} catch (AuthException e) {\n    // 'description' says why; on token errors refresh once and retry\n    token = miRequest.refresh(token).getData();\n    return miRequest.getUserInfo(token);\n}","preventionTips":["Store issuedAt + expiresIn and refresh before expiry","Handle refresh failure by forcing re-authorization","Request the profile permission scope in the Xiaomi console"],"tags":["oauth","xiaomi","token-expired","auth-exception"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}