Interface Authenticator



  • public interface Authenticator
    Responds to an authentication challenge from either a remote web server or a proxy server. Implementations may either attempt to satisfy the challenge by returning a request that includes an authorization header, or they may refuse the challenge by returning null. In this case the unauthenticated response will be returned to the caller that triggered it.

    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.

        String credential = Credentials.basic(...) return response.request().newBuilder() .header("Authorization", credential) .build(); 

    Whn 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.

        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.

    • Field Summary

      Fields

      Modifier and Type Field and Description
      static Authenticator NONE
      An authenticator that knows no credentials and makes no attempt to authenticate.
    • Method Summary

      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.
    • Field Detail

      • NONE

        static final Authenticator NONE
        An authenticator that knows no credentials and makes no attempt to authenticate.
    • Method Detail

      • authenticate

        Request authenticate(Route route,
                             Response response)
                      throws IOException
        Returns a request that includes a credential to satisfy an authentication challenge in response. Returns null if the challenge cannot be satisfied.
        Throws:
        IOException