Add devterm tools and TUI menu
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
This commit is contained in:
25
devterm/tools/jwt_tool.py
Normal file
25
devterm/tools/jwt_tool.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import jwt
|
||||
import json
|
||||
|
||||
|
||||
def decode_jwt(token: str, verify: bool = False) -> dict:
|
||||
try:
|
||||
parts = token.split(".")
|
||||
if len(parts) != 3:
|
||||
raise ValueError("Invalid JWT format")
|
||||
|
||||
header = json.loads(jwt.utils.base64url_decode(parts[0]).decode("utf-8"))
|
||||
payload = json.loads(jwt.utils.base64url_decode(parts[1]).decode("utf-8"))
|
||||
|
||||
result = {
|
||||
"header": header,
|
||||
"payload": payload,
|
||||
"signature": parts[2][:20] + "..." if len(parts[2]) > 20 else parts[2]
|
||||
}
|
||||
|
||||
if verify:
|
||||
jwt.decode(token, options={"verify_signature": False})
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
raise ValueError(f"Failed to decode JWT: {str(e)}")
|
||||
Reference in New Issue
Block a user