Skip to content

Commit c85f75a

Browse files
committed
Reviewed the quickstart and improved the READMEs. Updated the token binding check to make the pay claim mandatory to be in line with the latest changes in Approov.
Signed-off-by: Exadra37 <exadra37@gmail.com>
1 parent 1495fd3 commit c85f75a

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

docs/APPROOV_TOKEN_BINDING_QUICKSTART.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,9 @@ class ApproovMiddleware:
143143

144144
# @link https://approov.io/docs/latest/approov-usage-documentation/#token-binding
145145
def verifyApproovTokenBinding(self, request, approov_token_claims):
146-
# Note that the `pay` claim will, under normal circumstances, be present,
147-
# but if the Approov failover system is enabled, then no claim will be
148-
# present, and in this case you want to return true, otherwise you will not
149-
# be able to benefit from the redundancy afforded by the failover system.
150146
if not 'pay' in approov_token_claims:
151147
# You may want to add some logging here.
152-
return True
148+
return False
153149

154150
# We use the Authorization token, but feel free to use another header in
155151
# the request. Beqar in mind that it needs to be the same header used in the

src/approov-protected-server/token-binding-check/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,40 @@ Second, you need to set the dummy secret in the `src/approov-protected-server/to
4545

4646
Next, you need to install the dependencies. From the `src/approov-protected-server/token-binding-check` folder execute:
4747

48-
```text
48+
```bash
4949
python -m venv venv
5050
source venv/bin/activate
5151
pip3 install -r requirements.txt
5252
```
5353

5454
Now, you can run this example from the `src/approov-protected-server/token-binding-check` folder with:
5555

56-
```text
56+
```bash
5757
python manage.py runserver 8002
5858
```
5959

6060
> **NOTE:** If running inside a docker container use `0.0.0.0:8002`, otherwise Django will not answer requests from outside the container, like the ones you want to do from your browser.
6161
62+
Next, you can test that it works with:
63+
64+
```bash
65+
curl -iX GET 'http://localhost:8002'
66+
```
67+
68+
The response will be a `401` unauthorized request:
69+
70+
```text
71+
HTTP/1.1 401 Unauthorized
72+
Date: Wed, 23 Mar 2022 18:36:35 GMT
73+
Server: WSGIServer/0.2 CPython/3.10.3
74+
Content-Type: application/json
75+
Connection: close
76+
77+
{}
78+
```
79+
80+
The reason you got a `401` is because no Approoov token isn't provided in the headers of the request.
81+
6282
Finally, you can test that the Approov integration example works as expected with this [Postman collection](/README.md#testing-with-postman) or with some cURL requests [examples](/README.md#testing-with-curl).
6383

6484
[TOC](#toc---table-of-contents)

src/approov-protected-server/token-binding-check/hello/approov_middleware.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ def verifyApproovToken(self, request):
5555

5656
# @link https://approov.io/docs/latest/approov-usage-documentation/#token-binding
5757
def verifyApproovTokenBinding(self, request, approov_token_claims):
58-
# Note that the `pay` claim will, under normal circumstances, be present,
59-
# but if the Approov failover system is enabled, then no claim will be
60-
# present, and in this case you want to return true, otherwise you will not
61-
# be able to benefit from the redundancy afforded by the failover system.
6258
if not 'pay' in approov_token_claims:
6359
# You may want to add some logging here.
64-
return True
60+
return False
6561

6662
# We use the Authorization token, but feel free to use another header in
6763
# the request. Beqar in mind that it needs to be the same header used in the

src/approov-protected-server/token-check/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,48 @@ To run this example you will need to have Python installed. If you don't have th
3737

3838
First, you need to create the `.env` file. From the `src/approov-protected-server/token-check/hello` folder execute:
3939

40-
```
40+
```bash
4141
cp .env.example .env
4242
```
4343

4444
Second, you need to set the dummy secret in the `src/approov-protected-server/token-check/hello/.env` file as explained [here](/README.md#the-dummy-secret).
4545

4646
Next, you need to install the dependencies. From the `src/approov-protected-server/token-check` folder execute:
4747

48-
```text
48+
```bash
4949
python -m venv venv
5050
source venv/bin/activate
5151
pip3 install -r requirements.txt
5252
```
5353

5454
Now, you can run this example from the `src/approov-protected-server/token-check` folder with:
5555

56-
```text
56+
```bash
5757
python manage.py runserver 8002
5858
```
5959

6060
> **NOTE:** If running inside a docker container use `0.0.0.0:8002`, otherwise Django will not answer requests from outside the container, like the ones you want to do from your browser.
6161
62+
Next, you can test that it works with:
63+
64+
```bash
65+
curl -iX GET 'http://localhost:8002'
66+
```
67+
68+
The response will be a `401` unauthorized request:
69+
70+
```text
71+
HTTP/1.1 401 Unauthorized
72+
Date: Wed, 23 Mar 2022 18:36:35 GMT
73+
Server: WSGIServer/0.2 CPython/3.10.3
74+
Content-Type: application/json
75+
Connection: close
76+
77+
{}
78+
```
79+
80+
The reason you got a `401` is because no Approoov token isn't provided in the headers of the request.
81+
6282
Finally, you can test that the Approov integration example works as expected with this [Postman collection](/README.md#testing-with-postman) or with some cURL requests [examples](/README.md#testing-with-curl).
6383

6484
[TOC](#toc---table-of-contents)

0 commit comments

Comments
 (0)