> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JwtConfig

<span id="atoti.JwtConfig" />

> atoti.JwtConfig(<br />
>     \*,<br />
>     *key\_pair*: [KeyPair](./atoti.KeyPair#atoti.KeyPair) | [None](https://docs.python.org/3/library/constants.html#None) = `None`,<br />
> )

The JWT config.

Atoti uses JSON Web Tokens to authenticate requests between its components (e.g. between the app running in the browser and the session).

Creating a session with a custom JWT key pair:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> key_pair = generate_key_pair()
>>> jwt_config = tt.JwtConfig(key_pair=key_pair)
>>> session_config = tt.SessionConfig(security=tt.SecurityConfig(jwt=jwt_config))
>>> session = tt.Session.start(session_config)
```

Verifying the signature of a JWT issued by the session:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> from jwt import decode
>>> path, _ = session.client.get_path_and_version_id("activeviam/jwt")
>>> response = session.client.http_client.get(f"{path}/token").raise_for_status()
>>> body = response.json()
>>> jwt = body["token"]
>>> claims = decode(jwt, algorithms=["RS512"], key=key_pair.public_key_pem)
>>> claims["sub"]
'anonymousUser'
>>> sorted(claims["authorities"])
['ROLE_ADMIN', 'ROLE_ANONYMOUS', 'ROLE_USER']
```

### Attributes

<h4 id="atoti.JwtConfig.key_pair">
  *key\_pair*
</h4>

The key pair used to sign the JWT.

If `None`, a random 3072-bit key pair will be generated when the session starts.

Only RSA keys using the PKCS 8 standard are supported.
Key pairs can be generated using a library such as [cryptography](https://cryptography.io/en/latest/).
