Skip to content

Commit

Permalink
Merge pull request #36 from claroty/bugfix/abuddi/add-asyncpg-as-cpython
Browse files Browse the repository at this point in the history
Add asyncpg as cpython
  • Loading branch information
omerabuddi authored Aug 30, 2023
2 parents 9d1f038 + eb18194 commit 5994778
Show file tree
Hide file tree
Showing 5 changed files with 689 additions and 567 deletions.
2 changes: 1 addition & 1 deletion jwthenticator/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def authenticate(self) -> None:
:return: None or raises exception if fails.
"""
if self._key is None:
raise Exception("Missing key")
raise TypeError("Missing key")

url = urljoin(self.jwthenticator_server, "authenticate")
request = schemas.AuthRequest(self._key, self.identifier)
Expand Down
2 changes: 1 addition & 1 deletion jwthenticator/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class KeyData:
created: datetime
expires_at: datetime
key_hash: str
key: Optional[str] = field(default=None, repr=False, metadata=dict(load_only=True))
key: Optional[str] = field(default=None, repr=False, metadata={"load_only": True})

async def is_valid(self) -> bool:
return self.expires_at > datetime.utcnow()
Expand Down
6 changes: 3 additions & 3 deletions jwthenticator/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, public_key: str, private_key: Optional[str] = None, algorithm
"""
# This is done to avoid an "exploit" where algorithm=none leaving the jwt tokens unsecure.
if not algorithm or algorithm.lower() == "none":
raise Exception("Algorithm can't be empty!")
raise ValueError("Algorithm can't be empty!")

self.public_key = public_key
self.private_key = private_key
Expand All @@ -49,7 +49,7 @@ async def create_access_token(self, identifier: UUID) -> str:
:return: The new JWT token string
"""
if self.private_key is None:
raise Exception("Private key required for JWT token creation")
raise RuntimeError("Private key required for JWT token creation")
utc_now = datetime.utcnow()
payload = JWTPayloadData(
token_id=uuid4(),
Expand Down Expand Up @@ -84,7 +84,7 @@ async def create_refresh_token(self, key_id: int, expires_at: Optional[datetime]
if expires_at is None:
expires_at = expires_at = datetime.utcnow() + timedelta(seconds=REFRESH_TOKEN_EXPIRY)
if expires_at <= datetime.utcnow():
raise Exception("Refresh token can't be created in the past")
raise RuntimeError("Refresh token can't be created in the past")

refresh_token_str = sha512(uuid4().bytes).hexdigest()
async with self.async_session_factory() as session:
Expand Down
Loading

0 comments on commit 5994778

Please sign in to comment.