Skip to content

Commit

Permalink
Update python example to use PyJWT (#33797)
Browse files Browse the repository at this point in the history
Co-authored-by: Motaz <m-balghonaim@github.com>
Co-authored-by: Alex Nguyen <150945400+nguyenalex836@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 7, 2024
1 parent ed87739 commit d8579ea
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ puts jwt

{% note %}

**Note:** You must run `pip install jwt` to install the `jwt` package in order to use this script.
**Note:** You must run `pip install PyJWT` to install the `PyJWT` package in order to use this script.

{% endnote %}

```python copy
#!/usr/bin/env python3
from jwt import JWT, jwk_from_pem
import time
import sys
import time

import jwt


# Get PEM file path
Expand All @@ -117,7 +118,7 @@ else:

# Open PEM
with open(pem, 'rb') as pem_file:
signing_key = jwk_from_pem(pem_file.read())
signing_key = pem_file.read()

payload = {
# Issued at time
Expand All @@ -132,8 +133,7 @@ payload = {
}

# Create JWT
jwt_instance = JWT()
encoded_jwt = jwt_instance.encode(payload, signing_key, alg='RS256')
encoded_jwt = jwt.encode(payload, signing_key, algorithm='RS256')

print(f"JWT: {encoded_jwt}")
```
Expand Down

0 comments on commit d8579ea

Please sign in to comment.