Skip to content

Commit ab605fe

Browse files
Update README.md
1 parent 069e2ee commit ab605fe

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,56 @@ pip install guardpost[jwt]
3636

3737
For examples, refer to the [examples folder](./examples).
3838

39+
## Functions to validate JWTs
40+
41+
GuardPost includes functions to validate JSON Web Tokens (JWTs) and handle
42+
JSON Web Keys Sets (JWKS).
43+
44+
The built-in validator class can retrieve automatically JWKS from identity providers
45+
and handle automatically caching and keys rotation. Caching is useful to not incur in
46+
useless performance fees (e.g. downloading JWKS at each web request), and keys rotation
47+
is important because identity providers can periodically change the keys they use to
48+
sign JWTs.
49+
50+
To use these features, install to include additional dependencies:
51+
52+
```bash
53+
pip install guardpost[jwt]
54+
```
55+
56+
The following example shows how to use guardpost to validate tokens:
57+
58+
```python
59+
import asyncio
60+
from guardpost.jwts import JWTValidator
61+
62+
63+
async def main():
64+
validator = JWTValidator(
65+
authority="YOUR_AUTHORITY",
66+
valid_issuers=["YOUR_ISSUER_VALUE"],
67+
valid_audiences=["YOUR_AUDIENCE"],
68+
)
69+
70+
# keys are fetched when necessary
71+
data = await validator.validate_jwt("YOUR_TOKEN")
72+
73+
print(data)
74+
75+
76+
asyncio.run(main())
77+
```
78+
79+
An example value for `authority`, to validate access tokens issued by
80+
Azure Active Directory could be: `https://sts.windows.net/YOUR_TENANT_ID/`.
81+
82+
GuardPost is used in BlackSheep and has been tested with:
83+
84+
- Auth0
85+
- Azure Active Directory
86+
- Azure Active Directory B2C
87+
- Okta
88+
3989
## If you have doubts about authentication vs authorization...
4090
`Authentication` answers the question: _Who is the user who is initiating the
4191
action?_, or more in general: _Who is the user, or what is the service, that is

0 commit comments

Comments
 (0)