Created
November 18, 2017 18:49
-
-
Save zsmb13/01a5c27160a35b2d22c544c0a0a250dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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