Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a6a722

Browse files
committed
Universal method to set credentials via AsyncHttpClient interface, deprecated clearBasicAuth because it's not just about basic auth from now on
1 parent 38c088d commit 2a6a722

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,18 @@ public void setBasicAuth(String username, String password, AuthScope scope) {
650650
*/
651651
public void setBasicAuth(String username, String password, AuthScope scope, boolean preemtive) {
652652
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
653-
this.httpClient.getCredentialsProvider().setCredentials(scope == null ? AuthScope.ANY : scope, credentials);
653+
setCredentials(scope, credentials);
654654
setAuthenticationPreemptive(preemtive);
655655
}
656656

657+
public void setCredentials(AuthScope authScope, Credentials credentials) {
658+
if (credentials == null) {
659+
Log.d(LOG_TAG, "Provided credentials are null, not setting");
660+
return;
661+
}
662+
this.httpClient.getCredentialsProvider().setCredentials(authScope == null ? AuthScope.ANY : authScope, credentials);
663+
}
664+
657665
/**
658666
* Sets HttpRequestInterceptor which handles authorization in preemtive way, as workaround you
659667
* can use call `AsyncHttpClient.addHeader("Authorization","Basic base64OfUsernameAndPassword==")`
@@ -670,8 +678,18 @@ public void setAuthenticationPreemptive(boolean isPreemtive) {
670678

671679
/**
672680
* Removes previously set basic auth credentials
681+
*
682+
* @deprecated
673683
*/
684+
@Deprecated
674685
public void clearBasicAuth() {
686+
clearCredentialsProvider();
687+
}
688+
689+
/**
690+
* Removes previously set auth credentials
691+
*/
692+
public void clearCredentialsProvider() {
675693
this.httpClient.getCredentialsProvider().clear();
676694
}
677695

0 commit comments

Comments
 (0)