Created
September 23, 2013 03:33
-
-
Save davidmc24/6666237 to your computer and use it in GitHub Desktop.
Quick and dirty version of a Basic auth interceptor for Feign
This file contains hidden or 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 dagger.Module; | |
import dagger.Provides; | |
import feign.RequestInterceptor; | |
import feign.RequestTemplate; | |
import org.codehaus.groovy.runtime.EncodingGroovyMethods; | |
import java.nio.charset.StandardCharsets; | |
@Module(library = true) | |
public class BasicAuthenticationInterceptor implements RequestInterceptor { | |
private final String value; | |
public BasicAuthenticationInterceptor(final String username, final String password) { | |
value = "Basic " + EncodingGroovyMethods.encodeBase64((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1)).toString(); | |
} | |
@Override | |
public void apply(RequestTemplate template) { | |
template.header("Authorization", value); | |
} | |
@Provides(type = Provides.Type.SET) | |
public RequestInterceptor provideThis() { | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment