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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Note that the minimum OS requirement for iOS is 12 and for Android the minimum S
The Approov integration is available via [`pub-dev`](https://pub.dev/packages/approov_service_flutter_httpclient) package. This allows inclusion into the project by simply specifying a dependency in the `pubspec.yaml` files for the app. In the `dependencies:` section of `pubspec.yaml` file add the following package reference:

```yaml
approov_service_flutter_httpclient: ^3.5.5
approov_service_flutter_httpclient: ^3.5.8
```

This package is actually an open source wrapper layer that allows you to easily use Approov with `Flutter`. This has a further dependency to the closed source [Android Approov SDK](https://github.com/approov/approov-android-sdk) and [iOS Approov SDK](https://github.com/approov/approov-ios-sdk) packages. Those are automatically added as dependencies for the platform specific targets.
Expand Down Expand Up @@ -55,9 +55,11 @@ You must initialize the `ApproovService` as early as possible in the initializat
```Dart
import 'package:approov_service_flutter_httpclient/approov_service_flutter_httpclient.dart';
...
ApproovService.initialize('<enter-your-config-string-here>');
await ApproovService.initialize('<enter-your-config-string-here>');
```

The `initialize` method is asynchronous. Wait for it to complete (`await`) before you call any other `ApproovService` method, for example `addSubstitutionHeader`. A successful initialization resets the service configuration, so a configuration call made before it completes is lost. If initialization fails, `initialize` throws an `ApproovException`.

The `<enter-your-config-string-here>` is a custom string that configures your Approov account access. This will have been provided in your Approov onboarding email.

You can then create an `ApproovClient` when needed as follows:
Expand Down Expand Up @@ -120,7 +122,7 @@ Note that if you are using [Sentry](https://docs.sentry.io/platforms/flutter/) t
Note that it is possible to also use Approov from background isolates as well as the root isolate. This relies on support for [platform plugins in isolates
](https://docs.flutter.dev/perf/isolates#using-platform-plugins-in-isolates) that was introduced in Flutter 3.7. Note that you must follow the instructions given there regarding a call to `BackgroundIsolateBinaryMessenger.ensureInitialized` or else Approov will not work in the isolate.

Since each isolate has a completely independent state you must call `ApproovService.initialize` in each isolate. You should do this as soon as possible after its creation. Make sure you provide exactly the same `config` string provided in the root and all other isolates, since the underlying Approov SDK is shared between them all and can only have a single active configuration at one time. Note that the Approov implementation in the root isolate may be marginally faster than those in other isolates since it is able to use the method callbacks from native code which are not available to background isolates.
Since each isolate has a completely independent state you must call `ApproovService.initialize` in each isolate and wait for it to complete (`await`). You should do this as soon as possible after its creation. Make sure you provide exactly the same `config` string provided in the root and all other isolates, since the underlying Approov SDK is shared between them all and can only have a single active configuration at one time. Note that the Approov implementation in the root isolate may be marginally faster than those in other isolates since it is able to use the method callbacks from native code which are not available to background isolates.

## CHECKING IT WORKS
Initially you won't have set which API domains to protect, so the interceptor will not add anything. It will have called Approov though and made contact with the Approov cloud service. You will see logging from Approov saying `UNKNOWN_URL`.
Expand Down
8 changes: 5 additions & 3 deletions SHAPES-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ and change them as shown:
1. Add the dependency for the `approov_service_flutter_httpclient` package
```yaml
# *** UNCOMMENT THE SECTION BELOW FOR APPROOV ***
approov_service_flutter_httpclient: ^3.4.1
approov_service_flutter_httpclient: ^3.5.8
```

In the source file `quickstart-flutter-httpclient/example/lib/main.dart` find the two locations marked with a comment and change them:
Expand All @@ -116,9 +116,11 @@ import 'package:approov_service_flutter_httpclient/approov_service_flutter_httpc

```Dart
// *** UNCOMMENT THE LINE BELOW FOR APPROOV ***
ApproovService.initialize('<enter-your-config-string-here>');
await ApproovService.initialize('<enter-your-config-string-here>');
```

The `main` function is already `async`. Keep the `await`: a successful initialization resets the service configuration, so the `addSubstitutionHeader` call that follows it is lost if it runs before initialization completes.

The `<enter-your-config-string-here>` is a custom string that configures your Approov account access. This will have been provided in your Approov onboarding email.

3. Create an Approov Client:
Expand All @@ -138,7 +140,7 @@ final http.Client _client = ApproovClient();
//HttpClient client = HttpClient();

// *** UNCOMMENT THE TWO LINES BELOW FOR APPROOV ***
ApproovService.initialize('<enter-your-config-string-here>');
await ApproovService.initialize('<enter-your-config-string-here>');
HttpClient client = ApproovHttpClient();
```

Expand Down
10 changes: 7 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ const String SHAPE_URL = "https://shapes.approov.io/$API_VERSION/shapes";
// using SECRETS PROTECTION
const API_KEY = "yXClypapWNHIifHUWmBIyPFAm";

void main() {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

// *** UNCOMMENT THE LINE BELOW FOR APPROOV ***
//ApproovService.initialize('<enter-your-config-string-here>');
// Wait for initialization to complete before any other ApproovService call. A successful
// initialization resets the service configuration, so a call made before it completes is lost.
//await ApproovService.initialize('<enter-your-config-string-here>');

// *** UNCOMMENT THE LINE BELOW FOR APPROOV USING SECRETS PROTECTION ***
//ApproovService.addSubstitutionHeader("api-key", null);
Expand Down Expand Up @@ -158,7 +162,7 @@ class _ShapesState extends State<Shapes> {
HttpClient client = HttpClient();

// *** UNCOMMENT THE TWO LINES BELOW FOR APPROOV ***
//ApproovService.initialize('<enter-your-config-string-here>');
//await ApproovService.initialize('<enter-your-config-string-here>');
//HttpClient client = ApproovHttpClient();

// *** UNCOMMENT THE LINE BELOW FOR APPROOV USING SECRETS PROTECTION ***
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
logger: ^2.0.2

# *** UNCOMMENT THE LINES BELOW FOR APPROOV ***
#approov_service_flutter_httpclient: ^3.4.1
#approov_service_flutter_httpclient: ^3.5.8

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down
Loading