Skip to content

security

decode_token(token)

Decode a JSON Web Token (JWT).

This function takes a JSON Web Token (JWT) string and decodes it using the specified secret and algorithm. The decoded token data is returned, allowing further processing or validation.

Parameters:

Name Type Description Default
token str

The JWT string to decode.

required

Returns:

Type Description
dict

Decoded token data.

Source code in backend/app/security.py
def decode_token(token: str):
    """
    Decode a JSON Web Token (JWT).

    This function takes a JSON Web Token (JWT) string and decodes it using
    the specified secret and algorithm. The decoded token data is returned,
    allowing further processing or validation.

    :param token: The JWT string to decode.
    :type token: str
    :return: Decoded token data.
    :rtype: dict
    """
    token_data = jwt.decode(token, token_secret, algorithms=["HS256"])
    return token_data