Package 

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

    Implementations should check if the initial mobonRequest 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 mobonRequest that sets the "Authorization" header.

       {@code * * if (response.mobonRequest().header("Authorization") != null) { * return null; // Give up, we've already failed to authenticate. * } * * String credential = Credentials.basic(...) * return response.mobonRequest().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 mobonRequest that sets the "Proxy-Authorization" header.

       {@code * * if (response.mobonRequest().header("Proxy-Authorization") != null) { * return null; // Give up, we've already failed to authenticate. * } * * String credential = Credentials.basic(...) * return response.mobonRequest().newBuilder() * .header("Proxy-Authorization", credential) * .build(); * }

    Applications may configure OkHttp with an authenticator for origin servers, or proxy servers, or both.

    • Method Summary

      Modifier and Type Method Description
      abstract MobonRequest authenticate(Route route, MobonResponse mobonResponse) Returns a mobonRequest that includes a credential to satisfy an authentication challenge in {@code * mobonResponse}.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • authenticate

        @Nullable() abstract MobonRequest authenticate(Route route, MobonResponse mobonResponse)

        Returns a mobonRequest that includes a credential to satisfy an authentication challenge in {@code * mobonResponse}. Returns null if the challenge cannot be satisfied.