Skip to content

Commit

Permalink
fix: add types to verify_token and request __init__
Browse files Browse the repository at this point in the history
Recently, I've been using this library with mypy strict mode, which doesn't like the fact that these functions are unannotated (they're the only functions I use, and thus the only ones mypy complains about to me). I'm happy to see that this project has py.typed, so these annotations should fix the problem!
  • Loading branch information
wyattscarpenter committed Aug 20, 2024
1 parent c6d9903 commit ae25f47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Request(transport.Request):
.. automethod:: __call__
"""

def __init__(self, session=None):
def __init__(self, session: requests.Session | None = None) -> None:
if not session:
session = requests.Session()

Expand Down
15 changes: 9 additions & 6 deletions google/oauth2/id_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
from google.auth import environment_vars
from google.auth import exceptions
from google.auth import jwt
from google.auth import transport

from typing import Any, Mapping, Union


# The URL that provides public certificates for verifying ID tokens issued
Expand Down Expand Up @@ -104,12 +107,12 @@ def _fetch_certs(request, certs_url):


def verify_token(
id_token,
request,
audience=None,
certs_url=_GOOGLE_OAUTH2_CERTS_URL,
clock_skew_in_seconds=0,
):
id_token: Union[str, bytes],
request: transport.Request,
audience: str | list[str] | None = None,
certs_url: str = _GOOGLE_OAUTH2_CERTS_URL,
clock_skew_in_seconds: int = 0,
) -> Mapping[str, Any]:
"""Verifies an ID token and returns the decoded token.
Args:
Expand Down

0 comments on commit ae25f47

Please sign in to comment.