mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
WIP
This commit is contained in:
parent
312b21cb1e
commit
e4b57e8063
@ -29,6 +29,8 @@ import java.util.List;
|
||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||
import org.apache.commons.httpclient.auth.AuthScope;
|
||||
import org.apache.commons.httpclient.auth.AuthState;
|
||||
import org.apache.commons.httpclient.auth.BasicScheme;
|
||||
|
||||
public class OwnCloudBasicCredentials implements OwnCloudCredentials {
|
||||
|
||||
@ -50,6 +52,8 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials {
|
||||
|
||||
@Override
|
||||
public void applyTo(OwnCloudClient client) {
|
||||
AuthPolicy.registerAuthScheme(AuthState.PREEMPTIVE_AUTH_SCHEME, BasicScheme.class);
|
||||
|
||||
List<String> authPrefs = new ArrayList<String>(1);
|
||||
authPrefs.add(AuthPolicy.BASIC);
|
||||
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||
|
@ -28,48 +28,52 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||
import org.apache.commons.httpclient.auth.AuthScope;
|
||||
import org.apache.commons.httpclient.auth.AuthState;
|
||||
|
||||
import com.owncloud.android.lib.common.network.BearerAuthScheme;
|
||||
import com.owncloud.android.lib.common.network.BearerCredentials;
|
||||
|
||||
public class OwnCloudBearerCredentials implements OwnCloudCredentials {
|
||||
|
||||
private String mAccessToken;
|
||||
|
||||
public OwnCloudBearerCredentials(String accessToken) {
|
||||
mAccessToken = accessToken != null ? accessToken : "";
|
||||
}
|
||||
private String mUsername;
|
||||
private String mAccessToken;
|
||||
|
||||
@Override
|
||||
public void applyTo(OwnCloudClient client) {
|
||||
AuthPolicy.registerAuthScheme(BearerAuthScheme.AUTH_POLICY, BearerAuthScheme.class);
|
||||
|
||||
List<String> authPrefs = new ArrayList<String>(1);
|
||||
authPrefs.add(BearerAuthScheme.AUTH_POLICY);
|
||||
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||
|
||||
client.getParams().setAuthenticationPreemptive(true);
|
||||
public OwnCloudBearerCredentials(String username, String accessToken) {
|
||||
mUsername = username != null ? username : "";
|
||||
mAccessToken = accessToken != null ? accessToken : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(OwnCloudClient client) {
|
||||
AuthPolicy.registerAuthScheme(BearerAuthScheme.AUTH_POLICY, BearerAuthScheme.class);
|
||||
AuthPolicy.registerAuthScheme(AuthState.PREEMPTIVE_AUTH_SCHEME, BearerAuthScheme.class);
|
||||
|
||||
List<String> authPrefs = new ArrayList<>(1);
|
||||
authPrefs.add(BearerAuthScheme.AUTH_POLICY);
|
||||
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||
|
||||
client.getParams().setAuthenticationPreemptive(true); // true enforces BASIC AUTH ; library is stupid
|
||||
client.getParams().setCredentialCharset(OwnCloudCredentialsFactory.CREDENTIAL_CHARSET);
|
||||
client.getState().setCredentials(
|
||||
AuthScope.ANY,
|
||||
new BearerCredentials(mAccessToken)
|
||||
);
|
||||
}
|
||||
client.getState().setCredentials(
|
||||
AuthScope.ANY,
|
||||
new BearerCredentials(mAccessToken)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
// its unknown
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthToken() {
|
||||
return mAccessToken;
|
||||
}
|
||||
@Override
|
||||
public String getUsername() {
|
||||
// not relevant for authentication, but relevant for informational purposes
|
||||
return mUsername;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authTokenExpires() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String getAuthToken() {
|
||||
return mAccessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authTokenExpires() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class OwnCloudClientFactory {
|
||||
false);
|
||||
|
||||
client.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBearerCredentials(accessToken)
|
||||
OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken)
|
||||
);
|
||||
|
||||
} else if (isSamlSso) { // TODO avoid a call to getUserData here
|
||||
@ -161,7 +161,7 @@ public class OwnCloudClientFactory {
|
||||
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
|
||||
if (accessToken == null) throw new AuthenticatorException("WTF!");
|
||||
client.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBearerCredentials(accessToken)
|
||||
OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken)
|
||||
);
|
||||
|
||||
} else if (isSamlSso) { // TODO avoid a call to getUserData here
|
||||
|
@ -40,8 +40,8 @@ public class OwnCloudCredentialsFactory {
|
||||
return new OwnCloudBasicCredentials(username, password, preemptiveMode);
|
||||
}
|
||||
|
||||
public static OwnCloudCredentials newBearerCredentials(String authToken) {
|
||||
return new OwnCloudBearerCredentials(authToken);
|
||||
public static OwnCloudCredentials newBearerCredentials(String username, String authToken) {
|
||||
return new OwnCloudBearerCredentials(username, authToken);
|
||||
}
|
||||
|
||||
public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) {
|
||||
|
@ -48,6 +48,7 @@ public class AccountUtils {
|
||||
private static final String TAG = AccountUtils.class.getSimpleName();
|
||||
|
||||
public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
|
||||
public static final String ODAV_PATH = "/remote.php/webdav";
|
||||
public static final String STATUS_PATH = "/status.php";
|
||||
|
||||
/**
|
||||
@ -171,7 +172,7 @@ public class AccountUtils {
|
||||
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
|
||||
false);
|
||||
|
||||
credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken);
|
||||
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
|
||||
|
||||
} else if (isSamlSso) {
|
||||
String accessToken = am.blockingGetAuthToken(
|
||||
|
@ -26,6 +26,7 @@ package com.owncloud.android.lib.common.network;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.Credentials;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.auth.AuthChallengeParser;
|
||||
@ -33,6 +34,7 @@ import org.apache.commons.httpclient.auth.AuthScheme;
|
||||
import org.apache.commons.httpclient.auth.AuthenticationException;
|
||||
import org.apache.commons.httpclient.auth.InvalidCredentialsException;
|
||||
import org.apache.commons.httpclient.auth.MalformedChallengeException;
|
||||
import org.apache.commons.httpclient.util.EncodingUtil;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
@ -218,9 +220,15 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
|
||||
}
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(credentials.getAccessToken());
|
||||
|
||||
//return "Bearer " + EncodingUtil.getAsciiString(EncodingUtil.getBytes(buffer.toString(), charset));
|
||||
|
||||
Log_OC.v(TAG, "OAUTH2: string to authorize: " + "Bearer " + buffer.toString());
|
||||
return "Bearer " + buffer.toString();
|
||||
//return "Bearer " + EncodingUtil.getAsciiString(EncodingUtil.getBytes(buffer.toString(), charset));
|
||||
/*return "Bearer " + EncodingUtil.getAsciiString(
|
||||
Base64.encodeBase64(
|
||||
EncodingUtil.getBytes(buffer.toString(), charset)
|
||||
)
|
||||
);*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user