Use okhttp's Credentials class to build basic auth string

This commit is contained in:
xhh
2015-11-20 20:10:05 +08:00
committed by Alvin Zeng
parent 1d47ca69fe
commit 136d0aaa87
6 changed files with 48 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import com.migcomponents.migbase64.Base64;
import com.squareup.okhttp.Credentials;
import java.util.Map;
import java.util.List;
@@ -34,11 +34,8 @@ public class HttpBasicAuth implements Authentication {
if (username == null && password == null) {
return;
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
headerParams.put("Authorization", Credentials.basic(
username == null ? "" : username,
password == null ? "" : password));
}
}

View File

@@ -122,11 +122,6 @@
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>