2323import ch .cyberduck .core .Scheme ;
2424import ch .cyberduck .core .exception .BackgroundException ;
2525import ch .cyberduck .core .exception .LoginCanceledException ;
26- import ch .cyberduck .core .exception .LoginFailureException ;
2726
2827import org .apache .commons .lang3 .StringUtils ;
2928import 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