{"record":{"id":"7859b9ba807e790f","repo":"justauth/JustAuth","slug":"error-description-7859b9","errorCode":null,"errorMessage":"${error_description}","messagePattern":"\\$\\{error_description\\}","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java","lineNumber":102,"sourceCode":"     * @param state state 验证授权流程的参数，可以防止csrf\n     * @return 返回授权地址\n     * @since 1.9.3\n     */\n    @Override\n    public String authorize(String state) {\n        return UrlBuilder.fromBaseUrl(super.authorize(state))\n            .queryParam(\"scope\", this.getScopes(\",\", false, AuthScopeUtils.getDefaultScopes(AuthStackoverflowScope.values())))\n            .build();\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\"));\n        }\n    }\n}\n","sourceCodeStart":84,"sourceCodeEnd":106,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java#L84-L106","documentation":"AuthStackOverflowRequest.checkResponse throws AuthException with the raw `error_description` string whenever the Stack Exchange OAuth token/user response contains an `error` key. There is no numeric code; the message comes verbatim from Stack Exchange's error payload. It guards both the access-token exchange (POST /oauth/access_token) and the user-info call.","triggerScenarios":"Stack Exchange returns OAuth 2.0 style errors during getAccessToken or getUserInfo: expired/already-used authorization code, redirect_uri mismatch, bad client_secret, or an access token lacking the requested scope.","commonSituations":"redirectUri in AuthConfig differs from the one registered on stackapps.com (must match exactly, including trailing slash); reusing a code after a retry or double callback (a previous request consumed it); expired code (>5 min old or already exchanged); wrong client_id/secret after regenerating the app key.","solutions":["Compare the message with standard Stack Exchange OAuth errors: 'redirect_uri does not match' → fix redirectUri in AuthConfig to exactly the OAuth Domain registered on stackapps.com.","Ensure each authorization code is exchanged exactly once — guard your callback endpoint against duplicate invocations (browser retry, double-click).","Verify clientId ('Client Id') and clientSecret ('Client Secret') from your stackapps.com app page.","Exchange the code immediately after the callback; codes expire quickly."],"exampleFix":"// before\nAuthConfig.builder()\n    .redirectUri(\"https://example.com/callback\")\n    ...\n// registered OAuth Domain on stackapps.com is \"https://www.example.com/callback\"\n\n// after — byte-for-byte identical redirect\nAuthConfig.builder()\n    .redirectUri(\"https://www.example.com/callback\")\n    ...","handlingStrategy":"try-catch","validationCode":"// dedupe callbacks: never exchange one code twice\nString code = callback.getCode();\nif (!codeCache.putIfAbsent(code, true)) { // already seen\n    response.sendError(409, \"authorization code already used\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    AuthResponse<AuthUser> res = request.login(callback);\n} catch (AuthException e) {\n    log.warn(\"StackOverflow oauth failed: {}\", e.getMessage());\n    if (String.valueOf(e.getMessage()).contains(\"redirect_uri\")) {\n        throw new IllegalStateException(\"redirectUri mismatch with stackapps.com registration\", e);\n    }\n    throw e;\n}","preventionTips":["Keep the stackapps.com OAuth Domain and AuthConfig.redirectUri byte-identical.","Make the callback idempotent on the code parameter (cache seen codes for 10 minutes).","Exchange codes immediately; never pass codes through user-controllable retries."],"tags":["justauth","stack-overflow","oauth","redirect-uri","code-reuse"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}