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

Cleanup

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