public interface Authenticator
Implementations should check if the initial request already included an attempt to authenticate. If so it is likely that further attempts will not be useful and the authenticator should give up.
When authentication is requested by an origin server, the response code is 401 and the implementation should respond with a new request that sets the "Authorization" header.
if (response.request().header("Authorization") != null) {
return null; // Give up, we've already failed to authenticate.
}
String credential = Credentials.basic(...)
return response.request().newBuilder()
.header("Authorization", credential)
.build();
When authentication is requested by a proxy server, the response code is 407 and the implementation should respond with a new request that sets the "Proxy-Authorization" header.
if (response.request().header("Proxy-Authorization") != null) {
return null; // Give up, we've already failed to authenticate.
}
String credential = Credentials.basic(...)
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
Applications may configure OkHttp with an authenticator for origin servers, or proxy servers, or both.
Modifier and Type | Field and Description |
---|---|
static Authenticator |
NONE
An authenticator that knows no credentials and makes no attempt to authenticate.
|
Modifier and Type | Method and Description |
---|---|
Request |
authenticate(Route route,
Response response)
Returns a request that includes a credential to satisfy an authentication challenge in
response . |
static final Authenticator NONE
@Nullable Request authenticate(Route route, Response response) throws IOException
response
. Returns null if the challenge cannot be satisfied.IOException
Copyright © 2018. All rights reserved.