1 /* 2 * Copyright (C) 2013 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp; 17 18 import java.io.IOException; 19 import java.net.Proxy; 20 21 /** 22 * Responds to authentication challenges from the remote web or proxy server. 23 */ 24 public interface Authenticator { 25 /** 26 * Returns a request that includes a credential to satisfy an authentication 27 * challenge in {@code response}. Returns null if the challenge cannot be 28 * satisfied. This method is called in response to an HTTP 401 unauthorized 29 * status code sent by the origin server. 30 * 31 * <p>Typical implementations will look up a credential and create a request 32 * derived from the initial request by setting the "Authorization" header. 33 * <pre> {@code 34 * 35 * String credential = Credentials.basic(...) 36 * return response.request().newBuilder() 37 * .header("Authorization", credential) 38 * .build(); 39 * }</pre> 40 */ 41 Request authenticate(Proxy proxy, Response response) throws IOException; 42 43 /** 44 * Returns a request that includes a credential to satisfy an authentication 45 * challenge made by {@code response}. Returns null if the challenge cannot be 46 * satisfied. This method is called in response to an HTTP 407 unauthorized 47 * status code sent by the proxy server. 48 * 49 * <p>Typical implementations will look up a credential and create a request 50 * derived from the initial request by setting the "Proxy-Authorization" 51 * header. <pre> {@code 52 * 53 * String credential = Credentials.basic(...) 54 * return response.request().newBuilder() 55 * .header("Proxy-Authorization", credential) 56 * .build(); 57 * }</pre> 58 */ 59 Request authenticateProxy(Proxy proxy, Response response) throws IOException; 60 } 61