Skip to content

Commit 240dc72

Browse files
committed
Do not copy tokens.
1 parent 0d4517b commit 240dc72

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2ErrorResponseInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
public class OAuth2ErrorResponseInterceptor extends DisabledServiceUnavailableRetryStrategy {
2929
private static final Logger log = LogManager.getLogger(OAuth2ErrorResponseInterceptor.class);
3030

31+
private final Host host;
3132
private final OAuth2RequestInterceptor service;
3233

3334
public OAuth2ErrorResponseInterceptor(final Host host, final OAuth2RequestInterceptor service) {
35+
this.host = host;
3436
this.service = service;
3537
}
3638

@@ -40,7 +42,7 @@ public boolean retryRequest(final HttpResponse response, final int executionCoun
4042
case HttpStatus.SC_UNAUTHORIZED:
4143
try {
4244
log.warn("Attempt to refresh OAuth tokens for failure {}", response);
43-
service.save(service.refresh());
45+
service.save(service.refresh(host.getCredentials().getOauth()));
4446
// Try again
4547
return true;
4648
}

oauth/src/main/java/ch/cyberduck/core/oauth/OAuth2RequestInterceptor.java

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import ch.cyberduck.core.Scheme;
2424
import ch.cyberduck.core.exception.BackgroundException;
2525
import ch.cyberduck.core.exception.LoginCanceledException;
26-
import ch.cyberduck.core.exception.LoginFailureException;
2726

2827
import org.apache.commons.lang3.StringUtils;
2928
import org.apache.http.HttpException;
@@ -46,11 +45,7 @@ public class OAuth2RequestInterceptor extends OAuth2AuthorizationService impleme
4645
private static final Logger log = LogManager.getLogger(OAuth2RequestInterceptor.class);
4746

4847
private final ReentrantLock lock = new ReentrantLock();
49-
50-
/**
51-
* Currently valid tokens
52-
*/
53-
private OAuthTokens tokens;
48+
private final Host host;
5449

5550
public OAuth2RequestInterceptor(final HttpClient client, final Host host, final LoginCallback prompt) throws LoginCanceledException {
5651
this(client, host,
@@ -67,60 +62,14 @@ public OAuth2RequestInterceptor(final HttpClient client, final Host host, final
6762
public OAuth2RequestInterceptor(final HttpClient client, final Host host, final String tokenServerUrl, final String authorizationServerUrl,
6863
final String clientid, final String clientsecret, final List<String> scopes, final boolean pkce, final LoginCallback prompt) throws LoginCanceledException {
6964
super(client, host, tokenServerUrl, authorizationServerUrl, clientid, clientsecret, scopes, pkce, prompt);
70-
this.tokens = host.getCredentials().getOauth();
71-
}
72-
73-
@Override
74-
public OAuthTokens validate(final OAuthTokens saved) throws BackgroundException {
75-
return tokens = super.validate(saved);
76-
}
77-
78-
@Override
79-
public OAuthTokens authorize() throws BackgroundException {
80-
lock.lock();
81-
try {
82-
return tokens = super.authorize();
83-
}
84-
finally {
85-
lock.unlock();
86-
}
87-
}
88-
89-
/**
90-
* Refresh with cached refresh token
91-
*/
92-
public OAuthTokens refresh() throws BackgroundException {
93-
lock.lock();
94-
try {
95-
return tokens = this.refresh(tokens);
96-
}
97-
finally {
98-
lock.unlock();
99-
}
100-
}
101-
102-
/**
103-
* @param previous Refresh token
104-
*/
105-
@Override
106-
public OAuthTokens refresh(final OAuthTokens previous) throws BackgroundException {
107-
lock.lock();
108-
try {
109-
return tokens = super.refresh(previous);
110-
}
111-
catch(LoginFailureException e) {
112-
log.warn("Failure {} refreshing OAuth tokens", e.getMessage());
113-
return tokens = this.authorize();
114-
}
115-
finally {
116-
lock.unlock();
117-
}
65+
this.host = host;
11866
}
11967

12068
@Override
12169
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
12270
lock.lock();
12371
try {
72+
final OAuthTokens tokens = host.getCredentials().getOauth();
12473
if(tokens.isExpired()) {
12574
try {
12675
this.save(this.refresh(tokens));

0 commit comments

Comments
 (0)