Commit da352684 authored by Matija Obreza's avatar Matija Obreza

Merge branch '23-oauth-client-credentials' into 'master'

Resolve "OAuth Client Credentials"

Closes #23

See merge request !18
parents 104bcc14 5cd6c41f
......@@ -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>
......
......@@ -57,9 +57,9 @@ import java.util.Arrays;
public class SettingsDialog extends Dialog {
private static final String CUSTOM_SERVER_URL = "http://localhost:8080";
private static final String SANDBOX_SERVER_URL = "https://sandbox.genesys-pgr.org";
private static final String SANDBOX_SERVER_URL = "https://api.sandbox.genesys-pgr.org";
private static final String SANDBOX_CLIENT_ID = "Ap8Od.ydMSWlJ7qL9sJWtXXMCA@sandbox.genesys-pgr.org";
private static final String PRODUCTION_SERVER_URL = "https://www.genesys-pgr.org";
private static final String PRODUCTION_SERVER_URL = "https://api.genesys-pgr.org";
private static final String PRODUCTION_CLIENT_ID = "fTxcm.TrySiiiOLncyeWfmQKyp@www.genesys-pgr.org";
private Binding scope;
......@@ -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