Skip to content

Expose token expiration date #180

Open

Description

@TuburboMajus

I tried to find a way to retrieve the auth token expiration date but I was unsuccessful to do so. If it is possible please indicate me how can I access that information, and if it's not, exposing it can be a useful addition especially for long running automation that might get interrupted on token expiry. It will allow the program to raise an alert if that date approaches.

Activity

  1. Demohit139 commented on Aug 24, 2024

    @Demohit139

    auth token are generally in the form of jwt . it has 3 parts , so u have to split it and extract the expiration date from there

  2. Demohit139 commented on Aug 24, 2024

    @Demohit139

    auth token are generally in the form of jwt . it has 3 parts , so u have to split it and extract the expiration date from there

    import base64
    import json
    import time

    def decode_jwt(token):
    # JWT is usually in the format header.payload.signature
    _, payload, _ = token.split('.')

    # Add padding to the base64 string
    padded_payload = payload + '=' * (-len(payload) % 4)
    
    # Decode the payload
    decoded_payload = base64.urlsafe_b64decode(padded_payload)
    data = json.loads(decoded_payload)
    
    # Extract the expiration time (if available)
    if 'exp' in data:
        exp_time = data['exp']
        exp_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(exp_time))
        return exp_date
    else:
        return None
    

    #example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions