Commit 5cd6c41f authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

OAuth Client Credentials

parent 56b9c2c7
......@@ -63,11 +63,12 @@
<version>4.3</version>
<scope>provided</scope>
</dependency>
<!--<dependency> -->
<!--<groupId>org.eclipse.swt.gtk.linux</groupId> -->
<!--<artifactId>x86_64</artifactId> -->
<!--<version>3.3.0-v3346</version> -->
<!--</dependency> -->
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86_64</artifactId>
<version>3.3.0-v3346</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
......
......@@ -336,7 +336,7 @@ public class SettingsDialog extends Dialog {
try {
genesysClient = SpringConfig.createGenesysClient(oauthSettings);
} catch (IllegalArgumentException e) {
_log.error("Can't create Geneys API client", e);
_log.error("Can't create Genesys API client", e);
txtClientKey.forceFocus();
return;
}
......@@ -349,21 +349,31 @@ public class SettingsDialog extends Dialog {
SwtUtil.showMessageBox(getParent(), "OAuth", "Tokens are up to date.");
} catch (OAuthAuthenticationException e) {
_log.warn(e.getMessage());
String authorizationUrl = genesysClient.getAuthorizationUrl();
VerifierDialog vd = new VerifierDialog(getParent(), SWT.NONE);
String verifierCode = vd.open(authorizationUrl);
if (StringUtils.isNotBlank(verifierCode)) {
verifierCode = verifierCode.trim();
_log.info("Got verifier code: " + verifierCode);
try {
genesysClient.authenticate(verifierCode);
oauthSettings.setAccessToken(genesysClient.getTokens().getAccessToken());
oauthSettings.setRefreshToken(genesysClient.getTokens().getRefreshToken());
} catch (Throwable e1) {
_log.error(e1.getMessage(), e1);
SwtUtil.showMessageBox(getParent(), "OAuth error", e1.getMessage());
_log.info("Trying authenticate using clientKey and clientSecret");
try {
genesysClient.authenticate();
oauthSettings.setAccessToken(genesysClient.getTokens().getAccessToken());
oauthSettings.setRefreshToken(genesysClient.getTokens().getRefreshToken());
SwtUtil.showMessageBox(getParent(), "OAuth", "Tokens are up to date.");
} catch (OAuthAuthenticationException e1) {
_log.warn(e1.getMessage());
String authorizationUrl = genesysClient.getAuthorizationUrl();
VerifierDialog vd = new VerifierDialog(getParent(), SWT.NONE);
String verifierCode = vd.open(authorizationUrl);
if (StringUtils.isNotBlank(verifierCode)) {
verifierCode = verifierCode.trim();
_log.info("Got verifier code: " + verifierCode);
try {
genesysClient.authenticate(verifierCode);
oauthSettings.setAccessToken(genesysClient.getTokens().getAccessToken());
oauthSettings.setRefreshToken(genesysClient.getTokens().getRefreshToken());
} catch (Throwable e2) {
_log.error(e2.getMessage(), e2);
SwtUtil.showMessageBox(getParent(), "OAuth error", e2.getMessage());
}
}
}
} catch (HttpRedirectException e) {
......
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