Skip to content

expiry

Functions for verifying Keycloak tokens.

has_expired(token)

Check if a token has expired.

Does not check whether a token is valid or not, so might throw an exception.

Source code in dapla_team_cli/auth/services/expiry.py
 6
 7
 8
 9
10
11
12
13
def has_expired(token: str) -> bool:
    """Check if a token has expired.

    Does not check whether a token is valid or not, so might throw an exception.
    """
    decoded = jwt.decode(token, options={"verify_signature": False})
    expiry_date = pendulum.from_timestamp(decoded["exp"])
    return expiry_date < pendulum.now()