Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Mar 19, 2023
1 parent 7b93c5e commit b443467
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion auth0/authentication/async_token_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def _fetch_key(self, key_id=None):
key_id (str): The key's key id."""
return await self._fetcher.get_key(key_id)

async def verify_signature(self, token):
async def verify_signature(self, token) -> dict[str, Any]:
"""Verifies the signature of the given JSON web token.
Args:
Expand Down
4 changes: 2 additions & 2 deletions auth0/authentication/client_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
def create_client_assertion_jwt(
domain: str,
client_id: str,
client_assertion_signing_key: str | None,
client_assertion_signing_key: str,
client_assertion_signing_alg: str | None,
) -> str:
"""Creates a JWT for the client_assertion field.
Args:
domain (str): The domain of your Auth0 tenant
client_id (str): Your application's client ID
client_assertion_signing_key (str, optional): Private key used to sign the client assertion JWT
client_assertion_signing_key (str): Private key used to sign the client assertion JWT
client_assertion_signing_alg (str, optional): Algorithm used to sign the client assertion JWT (defaults to 'RS256')
Returns:
Expand Down
8 changes: 5 additions & 3 deletions auth0/authentication/token_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, algorithm: str) -> None:
raise ValueError("algorithm must be specified.")
self._algorithm = algorithm

def _fetch_key(self, key_id: str | None = None) -> str | RSAPublicKey:
def _fetch_key(self, key_id: str) -> str | RSAPublicKey:
"""Obtains the key associated to the given key id.
Must be implemented by subclasses.
Expand Down Expand Up @@ -111,6 +111,8 @@ def verify_signature(self, token: str) -> dict[str, Any]:
or the token's signature doesn't match the calculated one.
"""
kid = self._get_kid(token)
if kid is None:
kid = ""
secret_or_certificate = self._fetch_key(key_id=kid)

return self._decode_jwt(token, secret_or_certificate) # type: ignore[arg-type]
Expand All @@ -128,7 +130,7 @@ def __init__(self, shared_secret: str, algorithm: str = "HS256") -> None:
super().__init__(algorithm)
self._shared_secret = shared_secret

def _fetch_key(self, key_id: str | None = None) -> str:
def _fetch_key(self, key_id: str = "") -> str:
return self._shared_secret


Expand All @@ -144,7 +146,7 @@ def __init__(self, jwks_url: str, algorithm: str = "RS256") -> None:
super().__init__(algorithm)
self._fetcher = JwksFetcher(jwks_url)

def _fetch_key(self, key_id: str | None = None) -> RSAPublicKey:
def _fetch_key(self, key_id: str) -> RSAPublicKey:
return self._fetcher.get_key(key_id)


Expand Down
2 changes: 1 addition & 1 deletion auth0/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _calculate_wait(self, attempt: int) -> int:
wait = max(self.MIN_REQUEST_RETRY_DELAY(), wait)

self._metrics["retries"] = attempt
self._metrics["backoff"].append(wait)
self._metrics["backoff"].append(wait) # type: ignore[attr-defined]

return wait

Expand Down
5 changes: 2 additions & 3 deletions auth0/rest_async.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# mypy: disable-error-code=override
from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -115,8 +114,8 @@ async def post(
async def file_post(
self,
url: str,
data: dict[str, Any] | None = None,
files: dict[str, Any] | None = None,
data: dict[str, Any],
files: dict[str, Any],
) -> Any:
headers = self.base_headers.copy()
headers.pop("Content-Type", None)
Expand Down
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ ignore_errors = True

[mypy-auth0.management.*]
ignore_errors = True

[mypy-auth0.rest_async]
disable_error_code=override

[mypy-auth0.authentication.async_token_verifier]
disable_error_code=override, misc, attr-defined

0 comments on commit b443467

Please sign in to comment.