Skip to content

Commit

Permalink
fix datetime import
Browse files Browse the repository at this point in the history
  • Loading branch information
vaphes committed Jun 1, 2024
1 parent 71f121b commit d6c9bde
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pocketbase/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

import re
import datetime
from datetime import datetime
import base64
import datetime
import json
import re
from typing import Any


Expand All @@ -27,24 +26,26 @@ def normalize_base64(encoded_str):
encoded_str = encoded_str.strip()
padding_needed = len(encoded_str) % 4
if padding_needed:
encoded_str += '=' * (4 - padding_needed)
encoded_str += "=" * (4 - padding_needed)
return encoded_str


def validate_token(token: str) -> bool:
if len(token.split('.')) != 3:
if len(token.split(".")) != 3:
return False
decoded_bytes = base64.urlsafe_b64decode(normalize_base64(token.split('.')[1]))
decoded_str = decoded_bytes.decode('utf-8')
decoded_bytes = base64.urlsafe_b64decode(normalize_base64(token.split(".")[1]))
decoded_str = decoded_bytes.decode("utf-8")
data = json.loads(decoded_str)
exp = data["exp"]
if not isinstance(exp, int):
try:
exp = int(exp)
except ValueError or TypeError:
return False
current_time = datetime.now().timestamp()
current_time = datetime.datetime.now().timestamp()
return exp > current_time


class ClientResponseError(Exception):
url: str = ""
status: int = 0
Expand Down

0 comments on commit d6c9bde

Please sign in to comment.