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
9 changes: 3 additions & 6 deletions .github/workflows/screenshots-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ jobs:
arch: x86_64
profile: pixel_6
disable-animations: true
script: |
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/screenshot_test.dart \
--dart-define=ANALYTICS_PROPERTY_ID= \
-d emulator-5554
# One line: the action runs each script line as its own shell command,
# so a backslash-continued command falls apart.
script: flutter drive --driver=test_driver/integration_test.dart --target=integration_test/screenshot_test.dart --dart-define=ANALYTICS_PROPERTY_ID= -d emulator-5554

- name: Build the moksha job
run: |
Expand Down
24 changes: 23 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- appwrite >= 28 ships its own background push (MQTT foreground service,
flutter_background_service, boot receivers). Refetch delivers push
through FCM with the `push` plugin and never starts any of these, so
they are removed: a remoteMessaging foreground service would need a
Play Console foreground-service declaration, and the boot receivers
would wake the app at every reboot for nothing. The appwrite manifest
documents this removal for apps that do not use Push.setForeground. -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" tools:node="remove" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" tools:node="remove" />

<application
android:label="Refetch"
android:name="${applicationName}"
Expand Down Expand Up @@ -30,6 +43,15 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<!-- See the note at the top: appwrite's unused background push. -->
<service android:name="io.appwrite.flutter.services.PushService" tools:node="remove" />
<service android:name="io.appwrite.flutter.services.PushJobService" tools:node="remove" />
<receiver android:name="io.appwrite.flutter.services.PushAlarmReceiver" tools:node="remove" />
<receiver android:name="io.appwrite.flutter.services.PushBootReceiver" tools:node="remove" />
<activity android:name="io.appwrite.flutter.services.PushOpenActivity" tools:node="remove" />
<service android:name="id.flutter.flutter_background_service.BackgroundService" tools:node="remove" />
<receiver android:name="id.flutter.flutter_background_service.WatchdogReceiver" tools:node="remove" />
<receiver android:name="id.flutter.flutter_background_service.BootReceiver" tools:node="remove" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
Expand Down
8 changes: 5 additions & 3 deletions lib/core/network/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'api_exception.dart';
/// see the web repo's `docs/APP_API.md`).
///
/// Handles JSON encoding/decoding, unwrapping the `{ "data": … }` envelope,
/// error mapping to [ApiException], and injecting the cached Appwrite JWT as a
/// Bearer token on authenticated calls.
/// error mapping to [ApiException], and sending the cached Appwrite JWT in the
/// `X-Refetch-JWT` header on authenticated calls.
class ApiClient {
ApiClient({
required this.baseUrl,
Expand Down Expand Up @@ -88,7 +88,9 @@ class ApiClient {
if (token == null) {
throw const ApiException(401, 'You need to sign in to do that.');
}
headers['authorization'] = 'Bearer $token';
// Not `Authorization`: Appwrite Cloud's edge executor overwrites that
// header before the request reaches refetch.io (docs/APP_API.md).
headers['x-refetch-jwt'] = token;
}
return headers;
}
Expand Down
22 changes: 22 additions & 0 deletions test/api_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,26 @@ void main() {
),
);
});

// Appwrite Cloud's edge executor overwrites Authorization before the request
// reaches refetch.io, so the JWT must travel in X-Refetch-JWT.
test('sends the JWT in X-Refetch-JWT, not Authorization', () async {
Map<String, String>? sent;
when(
() => httpClient.post(
any(),
headers: any(named: 'headers'),
body: any(named: 'body'),
encoding: any(named: 'encoding'),
),
).thenAnswer((invocation) async {
sent = invocation.namedArguments[#headers] as Map<String, String>;
return http.Response('{"data":{}}', 200);
});

await api.post('/api/app/session');

expect(sent?['x-refetch-jwt'], 't');
expect(sent?.containsKey('authorization'), isFalse);
});
}