Commit e0d30b1a authored by Matija Obreza's avatar Matija Obreza
Browse files

setBaseUrl

parent 2b37d956
......@@ -57,11 +57,18 @@ public class GenesysClient {
private Token refreshToken;
private String apiUrl;
private GenesysApi genesysApi;
private GenesysApi genesysApi = new GenesysApi();
private String apiKey;
private String apiSecret;
public GenesysClient() {
}
public GenesysClient setBaseUrl(String baseUrl) {
genesysApi.setBaseUrl(baseUrl);
return this;
}
/**
* Load client configuration from {@link Properties}
*
......@@ -70,7 +77,7 @@ public class GenesysClient {
public void loadProperties(Properties properties) {
final String baseUrl = properties.getProperty("base.url");
this.genesysApi = new GenesysApi(baseUrl, properties.getProperty("client.key"), properties.getProperty("client.secret"));
genesysApi.setBaseUrl(baseUrl);
this.apiUrl = baseUrl + properties.getProperty("api.url");
final String httpAuth = properties.getProperty("http.auth");
......@@ -93,6 +100,8 @@ public class GenesysClient {
}
public void connect(String clientId, String clientSecret, String callback) {
this.apiKey = clientId;
this.apiSecret = clientSecret;
this.service = new ServiceBuilder().provider(this.genesysApi).apiKey(clientId).apiSecret(clientSecret).callback(callback).scope(SCOPE).build();
}
......@@ -184,7 +193,7 @@ public class GenesysClient {
if (this.refreshToken != null) {
_log.info("Using Refresh Token to get new access token");
try {
accessToken = genesysApi.getAccessToken(this.refreshToken);
accessToken = genesysApi.getAccessToken(this.apiKey, this.apiSecret, this.refreshToken);
_log.info("Got new Access Token!");
} catch (OAuthException e) {
_log.info("Refresh token didn't work: " + e.getMessage());
......
......@@ -40,17 +40,13 @@ public class GenesysApi extends DefaultApi20 {
private String scopedAuthorizeUrl;
private String accessTokenEndpoint;
private String refreshTokenEndpoint;
private String clientKey;
private String clientSecret;
public GenesysApi(String baseUrl, String clientKey, String clientSecret) {
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
this.authorizeUrl = this.baseUrl + AUTHORIZE_URL;
this.scopedAuthorizeUrl = this.authorizeUrl + "&scope=%s";
this.refreshTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT;
this.accessTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT + "?grant_type=authorization_code";
this.clientKey = clientKey;
this.clientSecret = clientSecret;
}
@Override
......@@ -94,10 +90,10 @@ public class GenesysApi extends DefaultApi20 {
*
* @throws OAuthAuthenticationException
*/
public Token getAccessToken(Token refreshToken) {
public Token getAccessToken(String apiKey, String apiSecret, Token refreshToken) {
OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientKey);
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, clientSecret);
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, apiKey);
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
request.addQuerystringParameter("grant_type", "refresh_token");
request.addQuerystringParameter("refresh_token", refreshToken.getToken());
Response response = request.send();
......
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