JWT Utilities
decode(token, key, algorithm, options={})
Decodes JWT token and returns payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
(str, required)
|
JWT token to decode. |
required |
key
|
(SecretStr | AllowedPublicKeyTypes, required)
|
Secret key to decode token with. |
required |
algorithm
|
(str, required)
|
Algorithm to decode token with. |
required |
options
|
Options
|
Options to decode token with. Defaults to {}. |
{}
|
Raises:
| Type | Description |
|---|---|
ExpiredSignatureError
|
If token is expired. |
InvalidTokenError
|
If token is invalid. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Decoded payload from JWT token. |
Source code in src/potato_util/crypto/jwt.py
encode(payload, key, algorithm)
Encodes payload into JWT token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
(dict[str, Any], required)
|
Payload to encode into token. |
required |
key
|
(SecretStr | AllowedPrivateKeyTypes, required)
|
Secret key to encode token with. |
required |
algorithm
|
(str, required)
|
Algorithm to encode token with. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'sub' is not provided in payload. |
ValueError
|
If 'jti' is not provided in payload. |
ValueError
|
If 'exp' is not provided in payload. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Encoded JWT token. |