Skip to content

Commit

Permalink
Merge pull request #3409 from nextcloud/bugfix/3408/fixLoginFailWithU…
Browse files Browse the repository at this point in the history
…mlautInUsername

Bugfix/3408/fix login fail with umlaut in username
  • Loading branch information
mahibi authored Oct 26, 2023
2 parents 3db8baa + 0e3c24b commit 0de2600
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
46 changes: 25 additions & 21 deletions app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.net.CookieManager;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -91,7 +92,7 @@ NcApi provideNcApi(Retrofit retrofit) {
@Provides
Proxy provideProxy(AppPreferences appPreferences) {
if (!TextUtils.isEmpty(appPreferences.getProxyType()) && !"No proxy".equals(appPreferences.getProxyType())
&& !TextUtils.isEmpty(appPreferences.getProxyHost())) {
&& !TextUtils.isEmpty(appPreferences.getProxyHost())) {
GetProxyRunnable getProxyRunnable = new GetProxyRunnable(appPreferences);
Thread getProxyThread = new Thread(getProxyRunnable);
getProxyThread.start();
Expand All @@ -111,10 +112,10 @@ Proxy provideProxy(AppPreferences appPreferences) {
@Provides
Retrofit provideRetrofit(OkHttpClient httpClient) {
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.client(httpClient)
.baseUrl("https://nextcloud.com")
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(LoganSquareConverterFactory.create());
.client(httpClient)
.baseUrl("https://nextcloud.com")
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(LoganSquareConverterFactory.create());

return retrofitBuilder.build();
}
Expand Down Expand Up @@ -207,11 +208,14 @@ OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences,
httpClient.proxy(proxy);

if (appPreferences.getProxyCredentials() &&
!TextUtils.isEmpty(appPreferences.getProxyUsername()) &&
!TextUtils.isEmpty(appPreferences.getProxyPassword())) {
httpClient.proxyAuthenticator(new HttpAuthenticator(Credentials.basic(
!TextUtils.isEmpty(appPreferences.getProxyUsername()) &&
!TextUtils.isEmpty(appPreferences.getProxyPassword())) {
httpClient.proxyAuthenticator(new HttpAuthenticator(
Credentials.basic(
appPreferences.getProxyUsername(),
appPreferences.getProxyPassword()), "Proxy-Authorization"));
appPreferences.getProxyPassword(),
StandardCharsets.UTF_8),
"Proxy-Authorization"));
}
}

Expand All @@ -225,7 +229,7 @@ OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences,
httpClient.addInterceptor(loggingInterceptor);
} else if (context.getResources().getBoolean(R.bool.nc_is_debug)) {
HttpLoggingInterceptor.Logger fileLogger =
s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s);
s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(fileLogger);
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
loggingInterceptor.redactHeader("Authorization");
Expand All @@ -243,11 +247,11 @@ public static class HeadersInterceptor implements Interceptor {
public Response intercept(@NonNull Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("User-Agent", ApiUtils.getUserAgent())
.header("Accept", "application/json")
.header("OCS-APIRequest", "true")
.method(original.method(), original.body())
.build();
.header("User-Agent", ApiUtils.getUserAgent())
.header("Accept", "application/json")
.header("OCS-APIRequest", "true")
.method(original.method(), original.body())
.build();

return chain.proceed(request);
}
Expand Down Expand Up @@ -282,8 +286,8 @@ public Request authenticate(@Nullable Route route, @NonNull Response response) {
}

return response.request().newBuilder()
.header(authenticatorType, credentials)
.build();
.header(authenticatorType, credentials)
.build();
}
}

Expand All @@ -299,12 +303,12 @@ private class GetProxyRunnable implements Runnable {
public void run() {
if (Proxy.Type.valueOf(appPreferences.getProxyType()) == Proxy.Type.SOCKS) {
proxy = new Proxy(Proxy.Type.valueOf(appPreferences.getProxyType()),
InetSocketAddress.createUnresolved(appPreferences.getProxyHost(), Integer.parseInt(
appPreferences.getProxyPort())));
InetSocketAddress.createUnresolved(appPreferences.getProxyHost(), Integer.parseInt(
appPreferences.getProxyPort())));
} else {
proxy = new Proxy(Proxy.Type.valueOf(appPreferences.getProxyType()),
new InetSocketAddress(appPreferences.getProxyHost(),
Integer.parseInt(appPreferences.getProxyPort())));
new InetSocketAddress(appPreferences.getProxyHost(),
Integer.parseInt(appPreferences.getProxyPort())));
}
}

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -60,8 +61,8 @@ public static String getUserAgent() {
}

/**
* @deprecated This is only supported on API v1-3, in API v4+ please use {@link ApiUtils#getUrlForAttendees(int,
* String, String)} instead.
* @deprecated This is only supported on API v1-3, in API v4+ please use
* {@link ApiUtils#getUrlForAttendees(int, String, String)} instead.
*/
@Deprecated
public static String getUrlForRemovingParticipantFromConversation(String baseUrl, String roomToken, boolean isGuest) {
Expand Down Expand Up @@ -399,7 +400,7 @@ public static String getCredentials(String username, String token) {
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) {
return null;
}
return Credentials.basic(username, token);
return Credentials.basic(username, token, StandardCharsets.UTF_8);
}

public static String getUrlNextcloudPush(String baseUrl) {
Expand Down

0 comments on commit 0de2600

Please sign in to comment.