mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-08 18:44:33 +00:00
docs(guides/integrate/service-users/private-key-jwt): (#7677)
* docs(guides/integrate/service-users/private-key-jwt): adjust incomplete, outdated and incorrect parts of the python example. * wrong variable name for kid in the header --------- Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
parent
25ef3da9d5
commit
fa9635eb93
@ -118,21 +118,27 @@ import datetime
|
||||
# Replace with your service user ID and private key
|
||||
service_user_id = "your_service_user_id"
|
||||
private_key = "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----"
|
||||
key_id = "your_key_id"
|
||||
|
||||
# ZITADEL API URL (replace if needed)
|
||||
api_url = "your_custom_domain"
|
||||
|
||||
# Generate JWT claims
|
||||
payload = {
|
||||
"iss": "your_zitadel_instance_id",
|
||||
"iss": service_user_id,
|
||||
"sub": service_user_id,
|
||||
"aud": api_url,
|
||||
"exp": datetime.utcnow() + datetime.timedelta(minutes=5),
|
||||
"iat": datetime.utcnow()
|
||||
"exp": datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(minutes=5),
|
||||
"iat": datetime.datetime.now(datetime.timezone.utc)
|
||||
}
|
||||
|
||||
header = {
|
||||
"alg": "RS256",
|
||||
"kid": key_id
|
||||
}
|
||||
|
||||
# Sign the JWT using RS256 algorithm
|
||||
encoded_jwt = jwt.encode(payload, private_key, algorithm="RS256")
|
||||
encoded_jwt = jwt.encode(payload, private_key, algorithm="RS256", headers=header)
|
||||
|
||||
print(f"Generated JWT: {encoded_jwt}")
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user