log.info("Trying to exchange OAuth token; isRefresh: " + isRefresh);
content = req.send(oAuthProvider.getTokenEndpoint(), HTTPMethod.POST);
} catch (InvalidStoreRequestException e) {
// if (isRefresh) {
log.log(Level.WARNING, "exchangeCodeForToken() failed; perhaps revoked", e);
throw new NeedNewOAuthTokenException("exchangeCodeForToken() failed; perhaps revoked", e);
// }
}
Pair<String, String> pair = oAuthProvider.parseNonStandardTokenResponse(content);
if (pair != null) {
return pair;
}
try {
JSONObject jsonObject = new JSONObject(content);
log.info(oAuthProvider.getTokenEndpoint() + " gave response body: " + jsonObject.toString());
if (!jsonObject.has("access_token")) {
throw new RuntimeException("No access token provided after exchangeOAuthCredentials");
}
return Pair.of(jsonObject.getString("access_token"), jsonObject.has("refresh_token")
? jsonObject.getString("refresh_token") : null);
} catch (JSONException e) {
// if (isRefresh) {
log.log(Level.WARNING, "exchangeCodeForToken() failed; perhaps revoked", e);
throw new NeedNewOAuthTokenException("exchangeCodeForToken() failed; perhaps revoked", e);
// }
}
}