{"record":{"id":"c4034aa75c11716f","repo":"justauth/JustAuth","slug":"error-description-c4034a","errorCode":null,"errorMessage":"${error_description}","messagePattern":"\\$\\{error_description\\}","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java","lineNumber":40,"sourceCode":" * @author yadong.zhang (yadong.zhang0415(a)gmail.com)\n * @since 1.0.0\n */\npublic class AuthWeiboRequest extends AuthDefaultRequest {\n\n    public AuthWeiboRequest(AuthConfig config) {\n        super(config, AuthDefaultSource.WEIBO);\n    }\n\n    public AuthWeiboRequest(AuthConfig config, AuthStateCache authStateCache) {\n        super(config, AuthDefaultSource.WEIBO, authStateCache);\n    }\n\n    @Override\n    public AuthToken getAccessToken(AuthCallback authCallback) {\n        String response = doPostAuthorizationCode(authCallback.getCode());\n        JSONObject accessTokenObject = JSONObject.parseObject(response);\n        if (accessTokenObject.containsKey(\"error\")) {\n            throw new AuthException(accessTokenObject.getString(\"error_description\"));\n        }\n        return AuthToken.builder()\n            .accessToken(accessTokenObject.getString(\"access_token\"))\n            .uid(accessTokenObject.getString(\"uid\"))\n            .openId(accessTokenObject.getString(\"uid\"))\n            .expireIn(accessTokenObject.getIntValue(\"expires_in\"))\n            .build();\n    }\n\n    @Override\n    public AuthUser getUserInfo(AuthToken authToken) {\n        String accessToken = authToken.getAccessToken();\n        String uid = authToken.getUid();\n        String oauthParam = String.format(\"uid=%s&access_token=%s\", uid, accessToken);\n\n        HttpHeader httpHeader = new HttpHeader();\n        httpHeader.add(\"Authorization\", \"OAuth2 \" + oauthParam);\n        httpHeader.add(\"API-RemoteIP\", IpUtils.getLocalIp());","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java#L22-L58","documentation":"AuthWeiboRequest.getAccessToken manually exchanges the authorization code (POST /oauth2/access_token) and, if the parsed JSON contains an `error` key, throws AuthException with the `error_description` value (message-only, no code). Weibo returns errors in the OAuth error format on the token endpoint.","triggerScenarios":"Weibo code exchange failing: expired or already-used authorization code, redirect_uri mismatch with the one registered on open.weibo.com, wrong client_id/client_secret (App Key/Secret), or the code issued for a different callback URL than configured.","commonSituations":"Weibo app's 授权回调页 not set or not matching AuthConfig.redirectUri exactly (protocol, host, path); double callback handling consuming the code twice; App Key/Secret regenerated after review process; Weibo enforcing HTTPS-only callbacks while config uses HTTP.","solutions":["Set the 授权回调页 (callback page) in open.weibo.com app settings to exactly the redirectUri in AuthConfig (full match including https and path).","Ensure the code is exchanged exactly once — dedupe callbacks, disable automatic browser re-POST.","Verify clientId=App Key, clientSecret=App Secret from the Weibo open platform console.","Use an HTTPS redirect_uri; Weibo rejects plain HTTP callbacks for most apps."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// assert config matches Weibo console before the flow starts\nif (!config.getRedirectUri().startsWith(\"https://\")) {\n    throw new IllegalArgumentException(\"Weibo requires an HTTPS redirect_uri\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    AuthToken t = weiboRequest.getAccessToken(callback);\n} catch (AuthException e) {\n    String m = String.valueOf(e.getMessage());\n    if (m.contains(\"redirect_uri\")) throw new ConfigurationException(\"Weibo callback page mismatch\", e);\n    if (m.contains(\"code\")) redirect(weiboRequest.authorize(newState())); // expired/reused code\n    else throw e;\n}","preventionTips":["Set 授权回调页 in open.weibo.com to the exact HTTPS redirectUri used in AuthConfig.","Deduplicate callback handling so each code is exchanged once.","Regenerate and sync App Key/Secret only through coordinated config updates."],"tags":["justauth","weibo","oauth","redirect-uri","code-reuse"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}