@Test public void emptyAuthHeaderIgnored() throws Exception { String accessToken = ""; when(authenticator.getAccessToken()).thenAnswer(invocation -> accessToken); Response response = interceptor.intercept(chain); Assert.assertNull(response.request().header("Authorization")); }
@Override public Response intercept(@NonNull Chain chain) throws IOException { final String token = authenticator.getAccessToken(); if (token.isEmpty()) { return chain.proceed(chain.request()); } final Request.Builder requestBuilder = chain.request().newBuilder(); final String authorization = Headers.AUTH_BEARER + token; requestBuilder.addHeader(Headers.AUTHORIZATION, authorization); return chain.proceed(requestBuilder.build()); }
RequestAuthInterceptor implements Interceptor { @Override public Response intercept(@NonNull Chain chain) throws IOException { final String token = authenticator.getAccessToken(); if (token.isEmpty()) { return chain.proceed(chain.request()); } final Request.Builder requestBuilder = chain.request().newBuilder(); final String authorization = Headers.AUTH_BEARER + token; requestBuilder.addHeader(Headers.AUTHORIZATION, authorization); return chain.proceed(requestBuilder.build()); } }
RequestAuthInterceptor implements Interceptor { @Override public Response intercept(@NonNull Chain chain) throws IOException { final String token = authenticator.getAccessToken(); if (token.isEmpty()) { return chain.proceed(chain.request()); } final Request.Builder requestBuilder = chain.request().newBuilder(); final String authorization = Headers.AUTH_BEARER + token; requestBuilder.addHeader(Headers.AUTHORIZATION, authorization); return chain.proceed(requestBuilder.build()); } @Inject  RequestAuthInterceptor(AccountAuthenticator authenticator); }
RequestAuthInterceptor implements Interceptor { @Override public Response intercept(@NonNull Chain chain) throws IOException { final String token = authenticator.getAccessToken(); if (token.isEmpty()) { return chain.proceed(chain.request()); } final Request.Builder requestBuilder = chain.request().newBuilder(); final String authorization = Headers.AUTH_BEARER + token; requestBuilder.addHeader(Headers.AUTHORIZATION, authorization); return chain.proceed(requestBuilder.build()); } @Inject  RequestAuthInterceptor(AccountAuthenticator authenticator); @Override Response intercept(@NonNull Chain chain); }
RequestAuthInterceptor implements Interceptor { @Override public Response intercept(@NonNull Chain chain) throws IOException { final String token = authenticator.getAccessToken(); if (token.isEmpty()) { return chain.proceed(chain.request()); } final Request.Builder requestBuilder = chain.request().newBuilder(); final String authorization = Headers.AUTH_BEARER + token; requestBuilder.addHeader(Headers.AUTHORIZATION, authorization); return chain.proceed(requestBuilder.build()); } @Inject  RequestAuthInterceptor(AccountAuthenticator authenticator); @Override Response intercept(@NonNull Chain chain);  }