{"record":{"id":"e5c8d6e820f1306d","repo":"justauth/JustAuth","slug":"object-getstring-error-description-e5c8d6","errorCode":null,"errorMessage":"object.getString(\"error_description\")","messagePattern":"object\\.getString\\(\"error_description\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java","lineNumber":168,"sourceCode":"    }\n\n    private String getUserName(JSONObject userInfoObject, String nameKey) {\n        String firstName;\n        JSONObject firstNameObj = userInfoObject.getJSONObject(nameKey);\n        JSONObject localizedObj = firstNameObj.getJSONObject(\"localized\");\n        JSONObject preferredLocaleObj = firstNameObj.getJSONObject(\"preferredLocale\");\n        firstName = localizedObj.getString(preferredLocaleObj.getString(\"language\") + \"_\" + preferredLocaleObj.getString(\"country\"));\n        return firstName;\n    }\n\n    /**\n     * 检查响应内容是否正确\n     *\n     * @param object 请求响应内容\n     */\n    private void checkResponse(JSONObject object) {\n        if (object.containsKey(\"error\")) {\n            throw new AuthException(object.getString(\"error_description\"), source);\n        }\n    }\n\n    /**\n     * 获取token，适用于获取access_token和刷新token\n     *\n     * @param accessTokenUrl 实际请求token的地址\n     * @return token对象\n     */\n    private AuthToken getToken(String accessTokenUrl) {\n        HttpHeader httpHeader = new HttpHeader();\n        httpHeader.add(\"Host\", \"www.linkedin.com\");\n        httpHeader.add(Constants.CONTENT_TYPE, \"application/x-www-form-urlencoded\");\n\n        String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader).getBody();\n        JSONObject accessTokenObject = JSONObject.parseObject(response);\n\n        this.checkResponse(accessTokenObject);","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java#L150-L186","documentation":"AuthLinkedinRequest.checkResponse throws AuthException(source=linkedin) with 'error_description' when the LinkedIn API response contains an 'error' key. This is LinkedIn's standard OAuth2 error body (invalid_grant, invalid_client, expired token, etc.).","triggerScenarios":"Token exchange, refresh, or GET /v2/me when LinkedIn returns {\"error\":\"...\",\"error_description\":\"...\"} — e.g. the 2019 API migration where old r_basicprofile scopes and v1 endpoints were retired.","commonSituations":"Using legacy scopes (r_basicprofile) instead of r_liteprofile/openid, expired or already-consumed auth code, wrong redirect URI not matching the LinkedIn app config, or an unapproved app requesting member permissions.","solutions":["Read error_description: 'we've made some changes...' style messages mean scope/endpoint migration is required (use r_liteprofile or OpenID Connect)","Match redirectUri exactly (scheme, host, path, trailing slash) with the LinkedIn app's OAuth 2.0 settings","Ensure the authorization code is exchanged within 30 seconds of issuance and only once","For restricted apps, request review of the member permissions before going live"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    linkedinRequest.getAuthResponse(callback);\n} catch (AuthException e) {\n    // error_description names the OAuth2 failure\n    if (e.getMessage() != null && e.getMessage().contains(\"expired\")) {\n        return redirectToAuthorize();\n    }\n    throw e;\n}","preventionTips":["Use openid or r_liteprofile scopes (post-2019 LinkedIn API), not r_basicprofile","Register the exact https redirect URI in the LinkedIn app","Exchange LinkedIn codes within seconds; they are extremely short-lived"],"tags":["oauth","linkedin","scope-migration","auth-exception"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}