Skip to content

Commit fbcdbfe

Browse files
authored
Improve detection of basic auth challenge (#69)
1 parent 6384677 commit fbcdbfe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/org/labkey/remoteapi/ApiKeyCredentialsProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
1919
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
2020
import org.apache.hc.client5.http.protocol.HttpClientContext;
21+
import org.apache.hc.core5.http.HttpStatus;
2122
import org.labkey.remoteapi.security.EnsureLoginCommand;
2223

2324
import java.io.IOException;
@@ -55,8 +56,7 @@ public boolean shouldRetryRequest(CommandException exception, HttpUriRequest req
5556
// requests should use the session. This mimics the behavior of BasicAuthCredentialsProvider.
5657

5758
String authHeaderValue = exception.getAuthHeaderValue();
58-
59-
boolean authChallenge = (null != authHeaderValue && authHeaderValue.startsWith("Basic realm") && "You must log in to view this content.".equals(exception.getMessage()));
59+
boolean authChallenge = (exception.getStatusCode() == HttpStatus.SC_UNAUTHORIZED && null != authHeaderValue && authHeaderValue.startsWith("Basic realm"));
6060

6161
if (authChallenge)
6262
request.setHeader("apikey", _apiKey);

0 commit comments

Comments
 (0)