You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+99-3Lines changed: 99 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,104 @@ A wrapper for the [Approov SDK](https://github.com/approov/approov-android-sdk)
4
4
5
5
See [Java](https://github.com/approov/quickstart-android-java-retrofit) and [Kotlin](https://github.com/approov/quickstart-android-kotlin-retrofit) quickstarts for instructions on how to use this.
6
6
7
+
## Adding Approov Service Dependency
8
+
The Approov integration is available via [`maven`](https://mvnrepository.com/repos/central). This allows inclusion into the project by simply specifying a dependency in the `gradle` files for the app.
9
+
The `Maven` repository is already present in the gradle.build file so the only import you need to make is the actual service layer itself:
Make sure you do a Gradle sync (by selecting `Sync Now` in the banner at the top of the modified `.gradle` file) after making these changes.
16
+
17
+
This package is actually an open source wrapper layer that allows you to easily use Approov with `Retrofit`. This has a further dependency to the closed source [Approov SDK](https://mvnrepository.com/artifact/io.approov/approov-android-sdk). In some cases you may need to also add this implementation to your dependencies list to avoid build errors:
Note that the minimum SDK version you can use with the Approov package is 23 (Android 6.0).
32
+
33
+
Please [read this](https://approov.io/docs/latest/approov-usage-documentation/#targeting-android-11-and-above) section of the reference documentation if targeting Android 11 (API level 30) or above.
34
+
35
+
## Initializing Approov Service
36
+
In order to use the `ApproovService` you must initialize it when your app is created, usually in the `onCreate` method:
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.
50
+
51
+
## Using Approov Service
52
+
You can then modify your code that obtains a `RetrofitInstance` to make API calls as follows:
This obtains a retrofit instance includes an `OkHttp` interceptor that protects channel integrity (with either pinning or managed trust roots). The interceptor may also add `Approov-Token` or substitute app secret values, depending upon your integration choices. You should thus use this client for all API calls you may wish to protect.
71
+
72
+
Approov errors will generate an `ApproovException`, which is a type of `IOException`. This may be further specialized into an `ApproovNetworkException`, indicating an issue with networking that should provide an option for a user initiated retry (which must make the new request with a call to the `getRetrofit` to get the latest client).
73
+
74
+
## Custom OkHttp Builder
75
+
By default, the Retrofit instance gets a default client constructed with a default `OkHttpClient`. However, your existing code may use a customized `OkHttpClient` with, for instance, different timeouts or other interceptors. For example, if you have existing code:
76
+
77
+
```kotlin
78
+
val client =OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build()
79
+
val retrofit = retrofit2.Retrofit.Builder().baseUrl("https://your.domain/").client(client).build()
80
+
```
81
+
Pass the modified `OkHttp.Builder` to the `ApproovService` as follows:
val retrofitBuilder = retrofit2.Retrofit.Builder().baseUrl("https://your.domain/")
86
+
val retrofit =ApproovService.getRetrofit(retrofitBuilder)
87
+
```
88
+
89
+
This call to `setOkHttpClientBuilder` only needs to be made once. Subsequent calls to `ApproovService.getRetrofit()` will then always a `OkHttpClient` with the builder values included.
90
+
91
+
## Checking it Works
92
+
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`.
93
+
94
+
Your Approov onboarding email should contain a link allowing you to access [Live Metrics Graphs](https://approov.io/docs/latest/approov-usage-documentation/#metrics-graphs). After you've run your app with Approov integration you should be able to see the results in the live metrics within a minute or so. At this stage you could even release your app to get details of your app population and the attributes of the devices they are running upon.
95
+
96
+
## Next Steps
97
+
To actually protect your APIs and/or secrets there are some further steps. Approov provides two different options for protection:
98
+
99
+
**API Protection** You should use this if you control the backend API(s) being protected and are able to modify them to ensure that a valid Approov token is being passed by the app. An [Approov Token](https://approov.io/docs/latest/approov-usage-documentation/#approov-tokens) is short lived crytographically signed JWT proving the authenticity of the call.
100
+
101
+
**Secrets Protection** This allows app secrets, including API keys for 3rd party services, to be protected so that they no longer need to be included in the released app code. These secrets are only made available to valid apps at runtime.
102
+
103
+
Note that it is possible to use both approaches side-by-side in the same app.
104
+
7
105
# Changelog
8
106
9
107
Please see the [CHANGELOG.md](CHANGELOG.md) for more information on the changes in each version.
@@ -18,9 +116,7 @@ Please see the [USAGE.md](USAGE.md) for more information on how to use this wrap
18
116
19
117
## Included 3rd party Source
20
118
21
-
To support message signing, this repo has adapted code released by two 3rd
22
-
party developers. The LICENSE files have been copied from the repos into the
23
-
associated directories listed below:
119
+
To support message signing, this repo has adapted code released by two 3rd party developers. The LICENSE files have been copied from the repos into the associated directories listed below:
0 commit comments