Commit 3ebc42f9 authored by Matija Obreza's avatar Matija Obreza

Throw OAuthException when refresh token no longer valid

parent 4e9423a0
......@@ -24,6 +24,7 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.genesys2.client.oauth.GenesysApiException;
import org.scribe.builder.api.DefaultApi20;
import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.extractors.JsonTokenExtractor;
import org.scribe.model.OAuthConfig;
......@@ -37,20 +38,20 @@ import org.scribe.utils.OAuthEncoder;
* Genesys API v1.
*/
public class GenesysApi extends DefaultApi20 {
/** The Constant _log. */
private static final Logger _log = LogManager.getLogger(GenesysApi.class);
/** OAuth2 authorization endpoint that is appended to {@link #baseUrl}. */
/** OAuth2 authorization endpoint that is appended to {@link #baseUrl}. */
public static final String AUTHORIZE_URL = "/oauth/authorize?client_id=%s&client_secret=%s&response_type=code&redirect_uri=%s";
/** OAuth2 access token endpoint that is appended to {@link #baseUrl}. */
/** OAuth2 access token endpoint that is appended to {@link #baseUrl}. */
private static final String TOKEN_ENDPOINT = "/oauth/token";
/** The base URL of the Genesys server (e.g. https://www.genesys-pgr.org) */
private String baseUrl;
/** The complete authorization url. */
/** The complete authorization url. */
private String authorizeUrl;
/** The scoped authorize url. */
......@@ -162,6 +163,8 @@ public class GenesysApi extends DefaultApi20 {
_log.debug("Redirect: " + response.getHeader(HttpHeaders.LOCATION));
if (response.getCode() >= 200 && response.getCode() < 300) {
return getAccessTokenExtractor().extract(response.getBody());
} else if (response.getCode() == 400) {
throw new OAuthException("Refresh token no longer valid.");
} else {
throw new GenesysApiException("Server responded with unexpected HTTP response code " + response.getCode());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment