{"record":{"id":"a9dba3949463ff43","repo":"justauth/JustAuth","slug":"accesstokenobject-getstring-error-description","errorCode":null,"errorMessage":"accessTokenObject.getString(\"error_description\")","messagePattern":"accessTokenObject\\.getString\\(\"error_description\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthMiRequest.java","lineNumber":51,"sourceCode":"        super(config, AuthDefaultSource.MI);\n    }\n\n    public AuthMiRequest(AuthConfig config, AuthStateCache authStateCache) {\n        super(config, AuthDefaultSource.MI, authStateCache);\n    }\n\n    @Override\n    public AuthToken getAccessToken(AuthCallback authCallback) {\n        return getToken(accessTokenUrl(authCallback.getCode()));\n    }\n\n    private AuthToken getToken(String accessTokenUrl) {\n        String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();\n        String jsonStr = response.replace(PREFIX, Constants.EMPTY);\n        JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);\n\n        if (accessTokenObject.containsKey(\"error\")) {\n            throw new AuthException(accessTokenObject.getString(\"error_description\"));\n        }\n\n        return AuthToken.builder()\n            .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);","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java#L33-L69","documentation":"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.","triggerScenarios":"Calling getAccessToken or refresh on AuthMiRequest when Xiaomi's account API rejects the grant: invalid code, wrong client secret, redirect mismatch, or missing scope.","commonSituations":"Xiaomi developer credentials misconfigured, authorization code older than its short TTL, or the app not published/approved on Xiaomi's developer console.","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"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    miRequest.getAuthResponse(callback);\n} catch (AuthException e) {\n    log.warn(\"Xiaomi token error: {}\", e.getMessage());\n    return redirectToLogin();\n}","preventionTips":["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"],"tags":["oauth","xiaomi","invalid-grant","auth-exception"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}