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

Sem-Ver: api-break Change the default token lifetime to be 1 minute - it was previously 1 hour #173

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ For example:
.. code:: python

import atlassian_jwt_auth
import requests
from atlassian_jwt_auth.contrib.requests import JWTAuth

signer = atlassian_jwt_auth.create_signer('issuer', 'issuer/key', private_key_pem, reuse_jwts=True)
Expand All @@ -113,6 +114,26 @@ For example:
auth=JWTAuth(signer, 'audience')
)

If you want to generate tokens with a longer lifetime than the default 1 minute period,
you can do so via specifying a `lifetime` value to `create_signer`.
For example:


.. code:: python

import datetime

import atlassian_jwt_auth
import requests
from atlassian_jwt_auth.contrib.requests import JWTAuth

signer = atlassian_jwt_auth.create_signer(
'issuer', 'issuer/key', private_key_pem,
reuse_jwts=True, lifetime=datetime.timedelta(minutes=2))
response = requests.get(
'https://your-url',
auth=JWTAuth(signer, 'audience')
)


To verify a JWT
Expand Down
2 changes: 1 addition & 1 deletion atlassian_jwt_auth/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class JWTAuthSigner(object):
def __init__(self, issuer, private_key_retriever, **kwargs):
self.issuer = issuer
self.private_key_retriever = private_key_retriever
self.lifetime = kwargs.get('lifetime', datetime.timedelta(hours=1))
self.lifetime = kwargs.get('lifetime', datetime.timedelta(minutes=1))
self.algorithm = kwargs.get('algorithm', 'RS256')
self.subject = kwargs.get('subject', None)
self._private_keys_cache = dict()
Expand Down
2 changes: 1 addition & 1 deletion atlassian_jwt_auth/tests/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test__generate_claims(self):
for additional_claims in [{}, {'extra': 'thing'}]:
expected_claims = {
'iss': expected_iss,
'exp': expected_now + datetime.timedelta(hours=1),
'exp': expected_now + datetime.timedelta(minutes=1),
'iat': expected_now,
'aud': expected_audience,
'nbf': expected_now,
Expand Down
Loading