Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose token expiration date #180

Open
TuburboMajus opened this issue Aug 9, 2024 · 2 comments
Open

Expose token expiration date #180

TuburboMajus opened this issue Aug 9, 2024 · 2 comments

Comments

@TuburboMajus
Copy link

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.

@Demohit139
Copy link

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

@Demohit139
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants