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: SHAPES-EXAMPLE.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Shapes Example
2
2
3
-
This quickstart is written specifically for native iOS and watchOS apps that are written in Swift for making the API calls that you wish to protect with Approov. This quickstart provides a step-by-step example of integrating Approov into an app using a simple `Shapes` example that shows a geometric shape based on a request to an API backend that can be protected with Approov.
3
+
This quickstart is written specifically for native iOS and watchOS apps that are written in Swift for making the API calls that you wish to protect with Approov. This quickstart provides a step-by-step example of integrating Approov into an app using a simple `Shapes` example that shows a geometric shape based on a request to an API backend that can be protected with Approov. The project targets both iOS and watchOS, allowing you to execute and integrate Approov independently for each platform.
4
4
5
5
## WHAT YOU WILL NEED
6
6
* Access to a trial or paid Approov account
@@ -19,22 +19,24 @@ Select your code signing certificate in the `Signing & Capabilities` tab and run
19
19
20
20
Once the application is running you will see two buttons:
This checks the connectivity by connecting to the endpoint `https://shapes.approov.io/v1/hello`. Now press the `Shape` button and you will see this (or another shape):
This contacts `https://shapes.approov.io/v1/shapes` to get the name of a random shape. This endpoint is protected with an API key that is built into the code, and therefore can be easily extracted from the app.
@@ -47,13 +49,13 @@ The Approov integration is available via the [`Swift Package Manager`](https://d
Enter the repository`https://github.com/approov/approov-service-urlsession.git` into the search box. You will then have to select the relevant version you wish to use. To do so, select the `Exact Version`, after which the latest `tag` from the selected repository should be selected. If you would like to use an earlier version, just replace the latest one.
52
+
Enter the repository`https://github.com/approov/approov-service-urlsession.git` into the search box. You will then have to select the relevant version you wish to use. To do so, select the `Exact Version`, after which the latest `tag` from the selected repository should be selected. If you would like to use an earlier version, just replace the latest one, but bear in mind that the combined watchOS and iOS support began with version `3.2.7`.
51
53
52
-
Once you click `Add Package` the last step will confirm the package product and target selection:
54
+
Once you click `Add Package` the last step will confirm the package product and target selection. Please, make sure you select a library for each one of your targets:
The `approov-service-urlsession` is actually an open source wrapper layer that allows you to easily use Approov with `URLSession`. This has a further dependency to the closed source [Approov SDK](https://github.com/approov/approov-ios-sdk).
58
+
The `approov-service-urlsession` is actually an open source wrapper layer that allows you to easily use Approov with `URLSession`. This has a further dependency to the closed source [Approov SDK](https://github.com/approov/approov-ios-sdk).
57
59
58
60
## ENSURE THE SHAPES API IS ADDED
59
61
@@ -67,20 +69,20 @@ Tokens for this domain will be automatically signed with the specific secret for
67
69
68
70
## MODIFY THE APP TO USE APPROOV
69
71
70
-
Before using Approov you need to import the `ApproovURLSession` Service. In the `ViewController.swift` source file import the service module:
72
+
Before using Approov you need to import the `ApproovURLSession` Service. In the `ViewController.swift`and/or `ContentView.swift`source file import the service module:
71
73
72
74
```swift
73
75
importApproovURLSession
74
76
```
75
77
76
-
Find the following line in `ViewController.swift` source file and uncomment it (commenting the previous definition):
78
+
Find the following line in `ViewController.swift`and `ContentView.swift`source file and uncomment it (commenting the previous definition):
77
79
78
80
```swift
79
81
//*** UNCOMMENT THE LINE BELOW FOR APPROOV
80
82
var defaultSession =ApproovURLSession(configuration: .default)
81
83
```
82
84
83
-
Now locate and uncomment the line inside the `viewDidLoad` function that initializes the `ApproovService` and remember to add the `config` parameter. The `approov-service-urlsession` needs a configuration string to identify the account associated with the app. You will have received this in your Approov onboarding email (it will be something like `#123456#K/XPlLtfcwnWkzv99Wj5VmAxo4CrU267J1KlQyoz8Qo=`):
85
+
Now locate and uncomment the line inside the `viewDidLoad`or `init`function that initializes the `ApproovService` and remember to add the `config` parameter. The `approov-service-urlsession` needs a configuration string to identify the account associated with the app. You will have received this in your Approov onboarding email (it will be something like `#123456#K/XPlLtfcwnWkzv99Wj5VmAxo4CrU267J1KlQyoz8Qo=`):
This means that the app is getting a validly signed Approov token to present to the shapes endpoint.
@@ -144,7 +147,7 @@ If you still don't get a valid shape then there are some things you can try. Rem
144
147
145
148
This section provides an illustration of an alternative option for Approov protection if you are not able to modify the backend to add an Approov Token check. We are still going to be using `https://shapes.approov.io/v1/shapes/` that simply checks for an API key, so please change back the code so it points to `https://shapes.approov.io/v1/shapes/`.
146
149
147
-
The `apiSecretKey` variable also needs to be changed as follows, removing the actual API key out of the code. Find this line and uncomment it (commenting the previosu definition):
150
+
The `apiSecretKey` variable also needs to be changed as follows, removing the actual API key out of the code. Find this line and uncomment it (commenting the previous definition):
148
151
149
152
```swift
150
153
//*** UNCOMMENT THE LINE BELOW FOR APPROOV USING SECRETS PROTECTION
@@ -172,6 +175,7 @@ Run the app again and press the `Get Shape` button. You should now see this (or
0 commit comments