Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.nextcloud.talk.account.data.model.LoginCompletion
import com.nextcloud.talk.account.data.model.LoginResponse
import com.nextcloud.talk.utils.ApiUtils
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -101,6 +102,7 @@ class NetworkLoginDataSource(val okHttpClient: OkHttpClient) {
.url(url)
.post(FormBody.Builder().build())
.addHeader("Clear-Site-Data", "cookies")
.header("User-Agent", ApiUtils.loginUserAgent)
.build()

okHttpClient.newCall(request).execute().use { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,13 @@ public static class HeadersInterceptor implements Interceptor {
public Response intercept(@NonNull Chain chain) throws IOException {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.header("User-Agent", ApiUtils.getUserAgent())
.header("ngrok-skip-browser-warning", "true")
.method(original.method(), original.body());

if (TextUtils.isEmpty(original.header("User-Agent"))) {
requestBuilder.header("User-Agent", ApiUtils.getUserAgent());
}

if (isOcsEndpoint(original)) {
requestBuilder
.header("Accept", "application/json")
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ object ApiUtils {
val userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v"
get() = field + BuildConfig.VERSION_NAME

private const val DEFAULT_LOGIN_PRODUCT_NAME = "Nextcloud Talk"

// shown to the user in the browser during the login flow, so it uses the human-readable product name
@JvmStatic
val loginUserAgent: String
get() {
val productName = sharedApplication?.resources?.getString(R.string.nc_app_product_name)
?: DEFAULT_LOGIN_PRODUCT_NAME
return "Mozilla/5.0 (Android) $productName v${BuildConfig.VERSION_NAME}"
}

@Deprecated(
"This is only supported on API v1-3, in API v4+ please use " +
"{@link ApiUtils#getUrlForAttendees(int, String, String)} instead."
Expand Down
Loading