From 8a7a2f4d1adcd3e209f63968e64b9e267526088d Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Tue, 22 Apr 2025 10:27:08 +0100 Subject: [PATCH 1/3] add user agent in header --- .../imispolicies/network/okhttp/AuthorizationInterceptor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java index beb1a458..cacbed09 100644 --- a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java +++ b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java @@ -15,6 +15,7 @@ public class AuthorizationInterceptor implements Interceptor { private static final String REQUESTED_WITH = "webapp"; + private static final String USER_AGENT = "mobile_app"; @NonNull private final LoginRepository repository; @@ -37,6 +38,7 @@ public Response intercept(@NonNull Chain chain) throws IOException { if(!StringUtils.isEmpty(csrfToken)){ builder.addHeader("X-Csrftoken", csrfToken); builder.addHeader("X-Requested-With", REQUESTED_WITH); + builder.addHeader("User-Agent", USER_AGENT); } Response response = chain.proceed(builder.build()); if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { From 294b9ccb092777e457f3ab2188400713c31bbcea Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Fri, 23 May 2025 10:26:07 +0100 Subject: [PATCH 2/3] fix csrf token on mobile app --- .../network/okhttp/AuthorizationInterceptor.java | 8 +------- .../imispolicies/network/request/BaseGraphQLRequest.java | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java index cacbed09..e2d39973 100644 --- a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java +++ b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java @@ -14,7 +14,6 @@ import okhttp3.Response; public class AuthorizationInterceptor implements Interceptor { - private static final String REQUESTED_WITH = "webapp"; private static final String USER_AGENT = "mobile_app"; @NonNull @@ -34,12 +33,7 @@ public Response intercept(@NonNull Chain chain) throws IOException { } Request.Builder builder = chain.request().newBuilder(); builder.addHeader("Authorization", "bearer " + token.trim()); - //builder.addHeader("Content-Type", "application/json"); - if(!StringUtils.isEmpty(csrfToken)){ - builder.addHeader("X-Csrftoken", csrfToken); - builder.addHeader("X-Requested-With", REQUESTED_WITH); - builder.addHeader("User-Agent", USER_AGENT); - } + builder.addHeader("User-Agent", USER_AGENT); Response response = chain.proceed(builder.build()); if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { repository.saveFhirToken(null, null, null); diff --git a/app/src/main/java/org/openimis/imispolicies/network/request/BaseGraphQLRequest.java b/app/src/main/java/org/openimis/imispolicies/network/request/BaseGraphQLRequest.java index e3dbc2f0..899047e4 100644 --- a/app/src/main/java/org/openimis/imispolicies/network/request/BaseGraphQLRequest.java +++ b/app/src/main/java/org/openimis/imispolicies/network/request/BaseGraphQLRequest.java @@ -31,7 +31,6 @@ public abstract class BaseGraphQLRequest { private static final ApolloClient apolloClient = ApolloClient.builder() .okHttpClient(OkHttpUtils.getDefaultOkHttpClient()) - .useHttpGetMethodForQueries(true) .serverUrl(URI) .addCustomTypeAdapter(CustomType.DATE, new DateCustomTypeAdapter()) .addCustomTypeAdapter(CustomType.DATETIME, new DateTimeCustomTypeAdapter()) From 73df3a7ab53a660941a11f4bfb206072f8bce50a Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Mon, 7 Jul 2025 10:19:54 +0100 Subject: [PATCH 3/3] re-add csrfToken in graphql request --- .../imispolicies/network/okhttp/AuthorizationInterceptor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java index e2d39973..b8a7af2a 100644 --- a/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java +++ b/app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java @@ -34,6 +34,9 @@ public Response intercept(@NonNull Chain chain) throws IOException { Request.Builder builder = chain.request().newBuilder(); builder.addHeader("Authorization", "bearer " + token.trim()); builder.addHeader("User-Agent", USER_AGENT); + if(!StringUtils.isEmpty(csrfToken)){ + builder.addHeader("X-Csrftoken", csrfToken); + } Response response = chain.proceed(builder.build()); if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { repository.saveFhirToken(null, null, null);