Commit 1e19babb authored by Matija Obreza's avatar Matija Obreza

Cleanup

parent d533b35b
...@@ -48,8 +48,7 @@ public class GenesysApi extends DefaultApi20 { ...@@ -48,8 +48,7 @@ public class GenesysApi extends DefaultApi20 {
this.authorizeUrl = this.baseUrl + AUTHORIZE_URL; this.authorizeUrl = this.baseUrl + AUTHORIZE_URL;
this.scopedAuthorizeUrl = this.authorizeUrl + "&scope=%s"; this.scopedAuthorizeUrl = this.authorizeUrl + "&scope=%s";
this.refreshTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT; this.refreshTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT;
this.accessTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT this.accessTokenEndpoint = this.baseUrl + TOKEN_ENDPOINT + "?grant_type=authorization_code";
+ "?grant_type=authorization_code";
this.clientKey = clientKey; this.clientKey = clientKey;
this.clientSecret = clientSecret; this.clientSecret = clientSecret;
} }
...@@ -66,12 +65,8 @@ public class GenesysApi extends DefaultApi20 { ...@@ -66,12 +65,8 @@ public class GenesysApi extends DefaultApi20 {
@Override @Override
public String getAuthorizationUrl(OAuthConfig config) { public String getAuthorizationUrl(OAuthConfig config) {
return config.hasScope() ? String.format(this.scopedAuthorizeUrl, return config.hasScope() ? String.format(this.scopedAuthorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()))
config.getApiKey(), config.getApiSecret(), : String.format(this.authorizeUrl, config.getApiKey(), config.getApiSecret(), OAuthEncoder.encode(config.getCallback()));
OAuthEncoder.encode(config.getCallback()),
OAuthEncoder.encode(config.getScope())) : String.format(
this.authorizeUrl, config.getApiKey(), config.getApiSecret(),
OAuthEncoder.encode(config.getCallback()));
} }
@Override @Override
...@@ -80,11 +75,9 @@ public class GenesysApi extends DefaultApi20 { ...@@ -80,11 +75,9 @@ public class GenesysApi extends DefaultApi20 {
} }
public Token getRefreshToken(Token accessToken) { public Token getRefreshToken(Token accessToken) {
Pattern refreshTokenPattern = Pattern Pattern refreshTokenPattern = Pattern.compile("\"refresh_token\":\\s*\"(\\S*?)\"");
.compile("\"refresh_token\":\\s*\"(\\S*?)\"");
Matcher matcher = refreshTokenPattern.matcher(accessToken Matcher matcher = refreshTokenPattern.matcher(accessToken.getRawResponse());
.getRawResponse());
if (matcher.find()) { if (matcher.find()) {
return new Token(matcher.group(1), "", accessToken.getRawResponse()); return new Token(matcher.group(1), "", accessToken.getRawResponse());
} }
...@@ -102,14 +95,11 @@ public class GenesysApi extends DefaultApi20 { ...@@ -102,14 +95,11 @@ public class GenesysApi extends DefaultApi20 {
* @throws OAuthAuthenticationException * @throws OAuthAuthenticationException
*/ */
public Token getAccessToken(Token refreshToken) { public Token getAccessToken(Token refreshToken) {
OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
this.refreshTokenEndpoint);
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientKey); request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientKey);
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, clientSecret);
clientSecret);
request.addQuerystringParameter("grant_type", "refresh_token"); request.addQuerystringParameter("grant_type", "refresh_token");
request.addQuerystringParameter("refresh_token", request.addQuerystringParameter("refresh_token", refreshToken.getToken());
refreshToken.getToken());
Response response = request.send(); Response response = request.send();
return getAccessTokenExtractor().extract(response.getBody()); return getAccessTokenExtractor().extract(response.getBody());
} }
......
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