---
title: "atlassian-jwt-auth | pypx"
description: "Python implementation of the Atlassian Service to Service Authentication specification."
canonical_url: "https://pypx.app/packages/atlassian-jwt-auth"
meta:
  "og:description": "Python implementation of the Atlassian Service to Service Authentication specification."
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_atlassian-jwt-auth%2Cversion_22.0.1%2Csummary_Python%2Bimplementation%2Bof%2Bthe%2BAtlassian%2BService%2Bto%2BService%2BAuthentication%2Bspecification.%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9hdGxhc3NpYW4tand0LWF1dGgi%2Cs_ZCXmOkMARxtihAnb.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "atlassian-jwt-auth 22.0.1"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_atlassian-jwt-auth%2Cversion_22.0.1%2Csummary_Python%2Bimplementation%2Bof%2Bthe%2BAtlassian%2BService%2Bto%2BService%2BAuthentication%2Bspecification.%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9hdGxhc3NpYW4tand0LWF1dGgi%2Cs_ZCXmOkMARxtihAnb.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **atlassian-jwt-auth**

v22.0.1

Python implementation of the Atlassian Service to Service Authentication specification.

53 KBpy2.py3-none-anyMIT License3 deps

[** Diff **](https://pypx.app/packages/atlassian-jwt-auth/diff)

`$ uv add atlassian-jwt-auth`

============================

# Atlassian JWT authentication

This package provides an implementation of the [Service to Service Authentication](https://s2sauth.bitbucket.io/spec/) specification.

\----

# Installation

To install simply run

```sh
$ pip install atlassian-jwt-auth
```

# Using this library

### To create a JWT for authentication

```python
import atlassian_jwt_auth


signer = atlassian_jwt_auth.create_signer('issuer', 'issuer/key', private_key_pem)
a_jwt = signer.generate_jwt('audience')
```

### To create a JWT using a file on disk in the conventional location

Each time you call generate\_jwt this will find the latest active key file (ends with .pem) and use it to generate your JWT.

```python
import atlassian_jwt_auth


signer = atlassian_jwt_auth.create_signer_from_file_private_key_repository('issuer', '/opt/jwtprivatekeys')
a_jwt = signer.generate_jwt('audience')
```

### To create a JWT using a data uri

```python
import atlassian_jwt_auth
from atlassian_jwt_auth.key import DataUriPrivateKeyRetriever

key_id, private_key_pem = DataUriPrivateKeyRetriever('Your base64 encoded data uri').load('issuer')
signer = atlassian_jwt_auth.create_signer('issuer', 'issuer/key', private_key_pem)
a_jwt = signer.generate_jwt('audience')
```

### To make an authenticated HTTP request

If you use the atlassian\_jwt\_auth.contrib.requests.JWTAuth provider, you can automatically generate JWT tokens when using the requests library to perform authenticated HTTP requests.

```python
import atlassian_jwt_auth
from atlassian_jwt_auth.contrib.requests import JWTAuth

signer = atlassian_jwt_auth.create_signer('issuer', 'issuer/key', private_key_pem)
response = requests.get(
    'https://your-url',
    auth=JWTAuth(signer, 'audience')
)
```

One can also use atlassian\_jwt\_auth.contrib.aiohttp.JWTAuth to authenticate aiohttp requests:

```python
import aiohttp

import atlassian_jwt_auth
from atlassian_jwt_auth.contrib.aiohttp import JWTAuth

signer = atlassian_jwt_auth.create_signer('issuer', 'issuer/key', private_key_pem)

async with aiohttp.ClientSession() as session:
    async with session.get('https://your-url',
                           auth=JWTAuth(signer, 'audience')) as resp:
        ...
```

If you want to reuse tokens that have the same claim within their period of validity then pass through `reuse_jwts=True` when calling `create_signer`. For example:

```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)
response = requests.get(
    'https://your-url',
    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:

```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

```python
import atlassian_jwt_auth

public_key_retriever = atlassian_jwt_auth.HTTPSPublicKeyRetriever('https://example.com')
verifier = atlassian_jwt_auth.JWTAuthVerifier(public_key_retriever)
verified_claims = verifier.verify_jwt(a_jwt, 'audience')
```

For Python versions starting from Python 3.5, note this library no longer supports python 3.5, atlassian\_jwt\_auth.contrib.aiohttp provides drop-in replacements for the components that perform HTTP requests, so that they use aiohttp instead of requests:

```python
import atlassian_jwt_auth.contrib.aiohttp

public_key_retriever = atlassian_jwt_auth.contrib.aiohttp.HTTPSPublicKeyRetriever('https://example.com')
verifier = atlassian_jwt_auth.contrib.aiohttp.JWTAuthVerifier(public_key_retriever)
verified_claims = await verifier.verify_jwt(a_jwt, 'audience')
```

## **Details **

<dl>

<dt>Version</dt>
<dd>22.0.1</dd>

<dt>License</dt>
<dd>MIT License</dd>

<dt>Maintainer</dt>
<dd>Atlassian</dd>

</dl>

## **Links**

- [Bug Tracker](https://github.com/atlassian/asap-authentication-python/issues)
- [Homepage](https://github.com/atlassian/asap-authentication-python)
- [Source Code](https://github.com/atlassian/asap-authentication-python)
- [View on PyPI](https://pypi.org/project/atlassian-jwt-auth/)

## **Release Cadence **

**3**

releases in the past year

avg 49 days between releases

## **Maintainers **

- Atlassian · [dblack@atlassian.com](mailto:dblack@atlassian.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/atlassian-jwt-auth#webpage","@type":"WebPage","description":"Python implementation of the Atlassian Service to Service Authentication specification.","name":"atlassian-jwt-auth","url":"https://pypx.app/packages/atlassian-jwt-auth","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/atlassian-jwt-auth"]}]},{"@id":"https://pypx.app/packages/atlassian-jwt-auth#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Python implementation of the Atlassian Service to Service Authentication specification.","license":"MIT License","name":"atlassian-jwt-auth","softwareVersion":"22.0.1"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
