1
0
mirror of https://github.com/etesync/android synced 2025-07-07 07:12:36 +00:00

Only add authentication if connecting to the service's hostname.

This commit is contained in:
Tom Hacohen 2017-02-14 15:11:55 +00:00
parent 4008776812
commit 833c8c0847

View File

@ -52,7 +52,7 @@ public class HttpClient {
// use account settings for authentication // use account settings for authentication
AccountSettings settings = new AccountSettings(context, account); AccountSettings settings = new AccountSettings(context, account);
builder = addAuthentication(builder, null, settings.getAuthToken()); builder = addAuthentication(builder, Constants.serviceUrl.getHost(), settings.getAuthToken());
return builder.build(); return builder.build();
} }
@ -136,8 +136,6 @@ public class HttpClient {
private static class TokenAuthenticator implements Interceptor { private static class TokenAuthenticator implements Interceptor {
protected static final String protected static final String
HEADER_AUTHORIZATION = "Authorization"; HEADER_AUTHORIZATION = "Authorization";
// FIXME: Host is not used
final String host, token; final String host, token;
@ -150,12 +148,16 @@ public class HttpClient {
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {
Request request = chain.request(); Request request = chain.request();
/* Only add to the host we want. */
if ((host == null)
|| (request.url().host().equals(host))) {
if ((token != null) if ((token != null)
&& (request.header(HEADER_AUTHORIZATION) == null)) { && (request.header(HEADER_AUTHORIZATION) == null)) {
request = request.newBuilder() request = request.newBuilder()
.header(HEADER_AUTHORIZATION, "Token " + token) .header(HEADER_AUTHORIZATION, "Token " + token)
.build(); .build();
} }
}
return chain.proceed(request); return chain.proceed(request);
} }