diff --git a/owncloud/pom.xml b/owncloud/pom.xml
index 5daa3acf0d8..a8271c5461d 100644
--- a/owncloud/pom.xml
+++ b/owncloud/pom.xml
@@ -39,6 +39,11 @@
webdav
${project.version}
+
+ ch.cyberduck
+ oauth
+ ${project.version}
+
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
diff --git a/owncloud/src/main/java/ch/cyberduck/core/owncloud/OwncloudSession.java b/owncloud/src/main/java/ch/cyberduck/core/owncloud/OwncloudSession.java
index 5ae68188c25..aa3d7f6c4df 100644
--- a/owncloud/src/main/java/ch/cyberduck/core/owncloud/OwncloudSession.java
+++ b/owncloud/src/main/java/ch/cyberduck/core/owncloud/OwncloudSession.java
@@ -17,8 +17,10 @@
import ch.cyberduck.core.Host;
import ch.cyberduck.core.ListService;
+import ch.cyberduck.core.LoginCallback;
import ch.cyberduck.core.UrlProvider;
import ch.cyberduck.core.dav.DAVSession;
+import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Home;
@@ -36,15 +38,49 @@
import ch.cyberduck.core.nextcloud.NextcloudShareProvider;
import ch.cyberduck.core.nextcloud.NextcloudUrlProvider;
import ch.cyberduck.core.nextcloud.NextcloudWriteFeature;
+import ch.cyberduck.core.oauth.OAuth2AuthorizationService;
+import ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor;
+import ch.cyberduck.core.oauth.OAuth2RequestInterceptor;
+import ch.cyberduck.core.proxy.Proxy;
import ch.cyberduck.core.ssl.X509KeyManager;
import ch.cyberduck.core.ssl.X509TrustManager;
+import ch.cyberduck.core.threading.CancelCallback;
+
+import org.apache.http.impl.client.HttpClientBuilder;
+
+import com.sun.tools.javac.comp.Flow;
+
+import static ch.cyberduck.core.oauth.OAuth2AuthorizationService.CYBERDUCK_REDIRECT_URI;
public class OwncloudSession extends DAVSession {
+ private OAuth2RequestInterceptor authorizationService;
+
public OwncloudSession(final Host host, final X509TrustManager trust, final X509KeyManager key) {
super(host, trust, key);
}
+ @Override
+ protected HttpClientBuilder getConfiguration(final Proxy proxy, final LoginCallback prompt) {
+ final HttpClientBuilder configuration = super.getConfiguration(proxy, prompt);
+ if(host.getProtocol().isOAuthConfigurable()) {
+ authorizationService = new OAuth2RequestInterceptor(configuration.build(), host)
+ .withFlowType(OAuth2AuthorizationService.FlowType.valueOf(host.getProtocol().getAuthorization()))
+ .withRedirectUri(CYBERDUCK_REDIRECT_URI);
+ configuration.addInterceptorLast(authorizationService);
+ configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
+ }
+ return configuration;
+ }
+
+ @Override
+ public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
+ if(host.getProtocol().isOAuthConfigurable()) {
+ authorizationService.authorize(host, prompt, cancel);
+ }
+ super.login(proxy, prompt, cancel);
+ }
+
@Override
@SuppressWarnings("unchecked")
public T _getFeature(final Class type) {
diff --git a/webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java b/webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java
index a3227034658..ace5c3a9d28 100644
--- a/webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java
+++ b/webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java
@@ -105,10 +105,14 @@ public DAVSession(final Host host, final X509TrustManager trust, final X509KeyMa
@Override
protected DAVClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
- // Always inject new pool to builder on connect because the pool is shutdown on disconnect
- final HttpClientBuilder pool = builder.build(proxy, this, prompt);
- pool.setRedirectStrategy(new DAVRedirectStrategy(redirect));
- return new DAVClient(new HostUrlProvider().withUsername(false).get(host), pool);
+ final HttpClientBuilder configuration = this.getConfiguration(proxy, prompt);
+ return new DAVClient(new HostUrlProvider().withUsername(false).get(host), configuration);
+ }
+
+ protected HttpClientBuilder getConfiguration(final Proxy proxy, final LoginCallback prompt) {
+ final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
+ configuration.setRedirectStrategy(new DAVRedirectStrategy(redirect));
+ return configuration;
}
@Override