Back to snippets

atlassian_jwt_auth_private_key_signing_quickstart.py

python

Creates a JWT signed with a private key to authenticate a request to

Agent Votes
1
0
100% positive
atlassian_jwt_auth_private_key_signing_quickstart.py
1import atlassian_jwt_auth
2
3# The private key for your application, usually loaded from a secure location.
4# It should be in PEM format.
5private_key_pem = """-----BEGIN RSA PRIVATE KEY-----
6...
7-----END RSA PRIVATE KEY-----"""
8
9# Information about your application and the target service
10issuer = 'my-application-key'
11key_id = 'my-application-key/key-id'
12audience = 'target-service-key'
13
14# Create a signer instance
15signer = atlassian_jwt_auth.create_signer(
16    issuer,
17    key_id,
18    private_key_pem
19)
20
21# Generate a signed JWT
22jwt_token = signer.generate_jwt(audience)
23
24# This token can now be used in the 'Authorization' header:
25# 'Authorization: JWT <jwt_token>'
26print(f"JWT {jwt_token}")