Skip to content

Instantly share code, notes, and snippets.

@raghunandankavi2010
Created February 12, 2019 14:34
Show Gist options
  • Save raghunandankavi2010/04a42d6ceffe2f98c18d879fdbc3deac to your computer and use it in GitHub Desktop.
Save raghunandankavi2010/04a42d6ceffe2f98c18d879fdbc3deac to your computer and use it in GitHub Desktop.
Okhttp authenticator
final OkHttpClient client = new OkHttpClient.Builder()
. authenticator(new Authenticator() {
@Override public Request authenticate(Route route, Response response) throws IOException {
if (response.request().header("Authorization") != null) {
return null; // Give up, we've already attempted to authenticate.
}
String credential = Credentials.basic("jesse", "password1");
return response.request().newBuilder()
.header("Authorization", credential)
.build();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment