Skip to content

Commit f08c576

Browse files
committed
Add types to missing parts and apply first mypy pass
1 parent da56c33 commit f08c576

9 files changed

Lines changed: 44 additions & 36 deletions

File tree

auth0/authentication/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def post(
6767
def authenticated_post(
6868
self,
6969
url: str,
70-
data: dict[str, Any] | None = None,
70+
data: dict[str, Any],
7171
headers: dict[str, str] | None = None,
7272
) -> Any:
7373
return self.client.post(

auth0/authentication/client_authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def add_client_authentication(
4444
payload: dict[str, Any],
4545
domain: str,
4646
client_id: str,
47-
client_secret: str,
47+
client_secret: str | None,
4848
client_assertion_signing_key: str | None,
4949
client_assertion_signing_alg: str | None,
5050
) -> dict[str, Any]:
@@ -54,7 +54,7 @@ def add_client_authentication(
5454
payload (dict): The POST payload that needs additional fields to be authenticated.
5555
domain (str): The domain of your Auth0 tenant
5656
client_id (str): Your application's client ID
57-
client_secret (str): Your application's client secret
57+
client_secret (str, optional): Your application's client secret
5858
client_assertion_signing_key (str, optional): Private key used to sign the client assertion JWT
5959
client_assertion_signing_alg (str, optional): Algorithm used to sign the client assertion JWT (defaults to 'RS256')
6060

auth0/authentication/database.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def signup(
2424
name: str | None = None,
2525
nickname: str | None = None,
2626
picture: str | None = None,
27-
) -> Any:
27+
) -> dict[str, Any]:
2828
"""Signup using email and password.
2929
3030
Args:
@@ -52,7 +52,7 @@ def signup(
5252
5353
See: https://auth0.com/docs/api/authentication#signup
5454
"""
55-
body = {
55+
body: dict[str, Any] = {
5656
"client_id": self.client_id,
5757
"email": email,
5858
"password": password,
@@ -73,13 +73,14 @@ def signup(
7373
if picture:
7474
body.update({"picture": picture})
7575

76-
return self.post(
76+
data: dict[str, Any] = self.post(
7777
f"{self.protocol}://{self.domain}/dbconnections/signup", data=body
7878
)
79+
return data
7980

8081
def change_password(
8182
self, email: str, connection: str, password: str | None = None
82-
) -> Any:
83+
) -> str:
8384
"""Asks to change a password for a given user.
8485
8586
email (str): The user's email address.
@@ -92,7 +93,8 @@ def change_password(
9293
"connection": connection,
9394
}
9495

95-
return self.post(
96+
data: str = self.post(
9697
f"{self.protocol}://{self.domain}/dbconnections/change_password",
9798
data=body,
9899
)
100+
return data

auth0/authentication/passwordless.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def email(
3939
auth_params (dict, optional): Parameters to append or override.
4040
"""
4141

42-
data = {
42+
data: dict[str, Any] = {
4343
"client_id": self.client_id,
4444
"connection": "email",
4545
"email": email,

auth0/authentication/token_verifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def verify_signature(self, token: str) -> dict[str, Any]:
113113
kid = self._get_kid(token)
114114
secret_or_certificate = self._fetch_key(key_id=kid)
115115

116-
return self._decode_jwt(token, secret_or_certificate)
116+
return self._decode_jwt(token, secret_or_certificate) # type: ignore[arg-type]
117117

118118

119119
class SymmetricSignatureVerifier(SignatureVerifier):
@@ -149,7 +149,7 @@ def __init__(self, jwks_url: str, cache_ttl: int = CACHE_TTL) -> None:
149149

150150
def _init_cache(self, cache_ttl: int) -> None:
151151
self._cache_value: dict[str, RSAPublicKey] = {}
152-
self._cache_date = 0
152+
self._cache_date = 0.0
153153
self._cache_ttl = cache_ttl
154154
self._cache_is_fresh = False
155155

auth0/authentication/users.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
15
from auth0.rest import RestClient, RestClientOptions
6+
from auth0.types import TimeoutType
27

38

49
class Users:
@@ -13,11 +18,11 @@ class Users:
1318

1419
def __init__(
1520
self,
16-
domain,
17-
telemetry=True,
18-
timeout=5.0,
19-
protocol="https",
20-
):
21+
domain: str,
22+
telemetry: bool = True,
23+
timeout: TimeoutType = 5.0,
24+
protocol: str = "https",
25+
) -> None:
2126
self.domain = domain
2227
self.protocol = protocol
2328
self.client = RestClient(
@@ -31,7 +36,7 @@ def __init__(
3136
domain (str): Your auth0 domain (e.g: username.auth0.com)
3237
"""
3338

34-
def userinfo(self, access_token):
39+
def userinfo(self, access_token: str) -> dict[str, Any]:
3540
"""Returns the user information based on the Auth0 access token.
3641
This endpoint will work only if openid was granted as a scope for the access_token.
3742
@@ -42,7 +47,8 @@ def userinfo(self, access_token):
4247
The user profile.
4348
"""
4449

45-
return self.client.get(
50+
data: dict[str, Any] = self.client.get(
4651
url=f"{self.protocol}://{self.domain}/userinfo",
4752
headers={"Authorization": f"Bearer {access_token}"},
4853
)
54+
return data

auth0/rest.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,20 @@ class RestClientOptions:
4141

4242
def __init__(
4343
self,
44-
telemetry: bool | None = None,
45-
timeout: TimeoutType | None = None,
46-
retries: int | None = None,
44+
telemetry: bool = True,
45+
timeout: TimeoutType = 5.0,
46+
retries: int = 3,
4747
) -> None:
48-
self.telemetry = True
49-
self.timeout = 5.0
50-
self.retries = 3
51-
52-
if telemetry is not None:
53-
self.telemetry = telemetry
54-
55-
if timeout is not None:
56-
self.timeout = timeout
57-
58-
if retries is not None:
59-
self.retries = retries
48+
self.telemetry = telemetry
49+
self.timeout = timeout
50+
self.retries = retries
6051

6152

6253
class RestClient:
6354
"""Provides simple methods for handling all RESTful api endpoints.
6455
6556
Args:
66-
jwt (str): The JWT to be used with the RestClient.
57+
jwt (str, optional): The JWT to be used with the RestClient.
6758
telemetry (bool, optional): Enable or disable Telemetry
6859
(defaults to True)
6960
timeout (float or tuple, optional): Change the requests
@@ -79,7 +70,7 @@ class RestClient:
7970

8071
def __init__(
8172
self,
82-
jwt: str,
73+
jwt: str | None,
8374
telemetry: bool = True,
8475
timeout: TimeoutType = 5.0,
8576
options: RestClientOptions | None = None,

auth0/rest_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# mypy: disable-error-code=override
12
from __future__ import annotations
23

34
import asyncio
@@ -36,7 +37,7 @@ class AsyncRestClient(RestClient):
3637

3738
def __init__(self, *args: Any, **kwargs: Any) -> None:
3839
super().__init__(*args, **kwargs)
39-
self._session = None
40+
self._session: aiohttp.ClientSession | None = None
4041
sock_connect, sock_read = (
4142
self.timeout
4243
if isinstance(self.timeout, tuple)

mypy.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[mypy]
2+
python_version = 3.7
3+
4+
[mypy-auth0.test.*,auth0.test_async.*]
5+
ignore_errors = True
6+
7+
[mypy-auth0.management.*]
8+
ignore_errors = True

0 commit comments

Comments
 (0)