use of com.owncloud.android.lib.common.authentication.OwnCloudCredentials in project android by owncloud.
the class PrepareVideoPlayerAsyncTask method buildHttpDataSourceFactory.
/**
* Returns a new HttpDataSource factory.
*
* @param bandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
* DataSource factory.
* @return A new HttpDataSource factory.
*/
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter, OCFile file, Account account) {
if (file.isDown()) {
return new DefaultHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter);
} else {
try {
OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(MainApp.Companion.getAppContext(), account);
String login = credentials.getUsername();
String password = credentials.getAuthToken();
Map<String, String> params = new HashMap<String, String>(1);
if (credentials instanceof OwnCloudBasicCredentials) {
// Basic auth
String cred = login + ":" + password;
String auth = "Basic " + Base64.encodeToString(cred.getBytes(), Base64.URL_SAFE);
params.put("Authorization", auth);
} else if (credentials instanceof OwnCloudBearerCredentials) {
// OAuth
String bearerToken = credentials.getAuthToken();
String auth = "Bearer " + bearerToken;
params.put("Authorization", auth);
}
return new CustomHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter, params);
} catch (AuthenticatorException | IOException | OperationCanceledException e) {
Timber.e(e);
}
}
return null;
}
Aggregations