Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update python example to use PyJWT #33797

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading