Skip to content

Latest commit

 

History

History

README.md

Approov Token Integration Example

This Approov integration example is from where the code example for the Approov token check quickstart is extracted, and you can use it as a playground to better understand how simple and easy it is to implement Approov in a Swift Vapor API server.

TOC - Table of Contents

Why?

To lock down your API server to your mobile app. Please read the brief summary in the Approov Overview at the root of this repo or visit our website for more details.

TOC

How it works?

The Swift server is very simple and is defined in this Vapor project /src/approov-protected-server/token-check/hello. Take a look at the verifyApproovToken() function to see the simple code for the check.

For more background on Approov, see the Approov Overview at the root of this repo.

TOC

Requirements

To run this example you will need to have Swift and Vapor toolbox installed. If you don't have then please follow the Vapor official installation instructions:

TOC

Setup Env File

From /src/approov-protected-server/token-check/hello execute the following:

cp .env.example .env

Edit the .env file and add the dummy secret to it in order to be able to test the Approov integration with the provided Postman collection.

TOC

Try the Approov Integration Example

Now you can run this example from the /src/approov-protected-server/token-check/hello folder with:

vapor run serve --port 8002

NOTE: If running from inside a docker container then you need to add --hostname 0.0.0.0 to the end of the command.

Next, you can test that it works with:

curl -iX GET 'http://localhost:8002'

The response will be a 401 unauthorized request:

HTTP/1.1 401 Unauthorized
content-length: 38
content-type: application/json; charset=utf-8
connection: keep-alive
date: Thu, 24 Mar 2022 20:20:38 GMT

{"reason":"Unauthorized","error":true}

The reason you got a 401 is because the Approoov token isn't provided in the headers of the request.

Finally, you can test that the Approov integration example works as expected with this Postman collection or with some cURL requests examples.

TOC

Issues

If you find any issue while following our instructions then just report it here, with the steps to reproduce it, and we will sort it out and/or guide you to the correct path.

TOC

Useful Links

If you wish to explore the Approov solution in more depth, then why not try one of the following links as a jumping off point:

TOC