Skip to content

Instantly share code, notes, and snippets.

@zsmb13
Created November 18, 2017 18:49
Show Gist options
  • Save zsmb13/01a5c27160a35b2d22c544c0a0a250dd to your computer and use it in GitHub Desktop.
Save zsmb13/01a5c27160a35b2d22c544c0a0a250dd to your computer and use it in GitHub Desktop.
import android.support.annotation.NonNull;
import com.example.app.BuildConfig;
import okhttp3.Credentials;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class BasicAuthInterceptor implements Interceptor {
private static final String AUTH_USER = BuildConfig.AUTH_USER;
private static final String AUTH_PASS = BuildConfig.AUTH_PASS;
@Override
public Response intercept(@NonNull final Chain chain) throws IOException {
final Request request = chain.request();
final Request newRequest = request.newBuilder()
.header("Authorization", Credentials.basic(AUTH_USER, AUTH_PASS))
.build();
return chain.proceed(newRequest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment