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 PHP API server.
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.
The PHP server is very simple and is defined in the file src/approov-protected-server/token-check/hello-server-protected.php. 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.
To run this example you will need to have PHP installed. If you don't have then please follow the official installation instructions from here to download and install it.
First, you need to set the dummy secret in the src/approov-protected-server/token-check/.env
file as explained here.
Second, you need to install the dependencies. From the src/approov-protected-server/token-check
folder execute:
composer install
Now, you can run this example from the src/approov-protected-server/token-check
folder with:
php -S localhost:8002 hello-server-protected.php
NOTE: If running from inside a docker container you need to start the server with
0.0.0.0:8002
, instead oflocalhost:8002
.
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
Host: localhost:8002
Date: Tue, 22 Mar 2022 16:09:47 GMT
Connection: close
X-Powered-By: PHP/8.1.4
Content-Type: application/json
Content-Length: 2
{}
The reason you got a 401
is because no 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.
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.
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: