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