justauth/JustAuth · error · AuthException

Failed to get token from Renren:

Error message

Failed to get token from Renren: 

What it means

AuthRenrenRequest.getToken throws AuthException with message 'Failed to get token from Renren: ' + full JSON body when the Renren token/refresh response contains an 'error' key. Renren's OAuth2 returns an error object with code/description for failed grants.

Source

Thrown at src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java:74

            .gender(getGender(userObj))
            .token(authToken)
            .source(source.toString())
            .build();
    }

    @Override
    public AuthResponse<AuthToken> refresh(AuthToken authToken) {
        return AuthResponse.<AuthToken>builder()
            .code(SUCCESS.getCode())
            .data(getToken(this.refreshTokenUrl(authToken.getRefreshToken())))
            .build();
    }

    private AuthToken getToken(String url) {
        String response = new HttpUtils(config.getHttpConfig()).post(url).getBody();
        JSONObject jsonObject = JSONObject.parseObject(response);
        if (jsonObject.containsKey("error")) {
            throw new AuthException("Failed to get token from Renren: " + jsonObject);
        }

        return AuthToken.builder()
            .tokenType(jsonObject.getString("token_type"))
            .expireIn(jsonObject.getIntValue("expires_in"))
            .accessToken(UrlUtil.urlEncode(jsonObject.getString("access_token")))
            .refreshToken(UrlUtil.urlEncode(jsonObject.getString("refresh_token")))
            .openId(jsonObject.getJSONObject("user").getString("id"))
            .build();
    }

    private String getAvatarUrl(JSONObject userObj) {
        JSONArray jsonArray = userObj.getJSONArray("avatar");
        if (Objects.isNull(jsonArray) || jsonArray.isEmpty()) {
            return null;
        }
        return jsonArray.getJSONObject(0).getString("url");
    }

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Read the embedded JSON in the message — Renren's error object names the cause
  2. Verify clientId/clientSecret/redirectUri against the Renren developer console (if still accessible)
  3. Make the callback idempotent so the one-time code is not exchanged twice
  4. If Renren has sunset the API for your app, retire the Renren login option

Example fix

null
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

try {
    renrenRequest.getAuthResponse(callback);
} catch (AuthException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Failed to get token from Renren")) {
        // parse embedded JSON, and fall back to other login providers
        log.warn("Renren OAuth unavailable: {}", e.getMessage());
        return fallbackToOtherProviders();
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling getAccessToken or refresh when Renren rejects the grant: invalid authorization code, wrong client secret, or redirect_uri mismatch. The whole response JSON is embedded in the exception message.

Common situations: Renren's open platform has been largely deprecated; many developers hit this because the service or their registered app is no longer active, or credentials rotted. Also common: code exchanged twice due to double callback hits.

Related errors


AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14). Data as JSON: /api/errors/5762fb31d0ffee42. Report an issue: GitHub.