Skip to content

Commit 2bdbb46

Browse files
committed
Add fallback to restart flow on invalid OAuth tokens.
1 parent d699b20 commit 2bdbb46

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

s3/src/main/java/ch/cyberduck/core/sts/STSAssumeRoleWithWebIdentityRequestInterceptor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ch.cyberduck.core.Profile;
2222
import ch.cyberduck.core.TemporaryAccessTokens;
2323
import ch.cyberduck.core.exception.BackgroundException;
24+
import ch.cyberduck.core.exception.LoginFailureException;
2425
import ch.cyberduck.core.oauth.OAuth2RequestInterceptor;
2526
import ch.cyberduck.core.preferences.ProxyPreferencesReader;
2627
import ch.cyberduck.core.s3.S3CredentialsStrategy;
@@ -58,13 +59,18 @@ public STSAssumeRoleWithWebIdentityRequestInterceptor(final OAuth2RequestInterce
5859
@Override
5960
public TemporaryAccessTokens refresh(final Credentials credentials) throws BackgroundException {
6061
lock.lock();
62+
final String arn = new ProxyPreferencesReader(host, credentials).getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn");
63+
log.debug("Use ARN {}", arn);
6164
try {
62-
final String arn = new ProxyPreferencesReader(host, credentials).getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn");
63-
log.debug("Use ARN {}", arn);
6465
return tokens = this.assumeRoleWithWebIdentity(oauth.validate(credentials.getOauth()), arn);
6566
}
67+
catch(LoginFailureException e) {
68+
// Expired or invalid OAuth tokens
69+
log.warn("Failure {} authorizing. Retry with refreshed OAuth tokens", e.getMessage());
70+
return this.tokens = this.assumeRoleWithWebIdentity(oauth.authorize(), arn);
71+
}
6672
finally {
6773
lock.unlock();
6874
}
6975
}
70-
}
76+
}

0 commit comments

Comments
 (0)