From ae25f47a7eec97c9a3f78559a7288dbcfe775f5d Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Tue, 20 Aug 2024 14:27:12 -0700 Subject: [PATCH] fix: add types to verify_token and request __init__ 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! --- google/auth/transport/requests.py | 2 +- google/oauth2/id_token.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/google/auth/transport/requests.py b/google/auth/transport/requests.py index 68f67c59b..3a38357a3 100644 --- a/google/auth/transport/requests.py +++ b/google/auth/transport/requests.py @@ -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() diff --git a/google/oauth2/id_token.py b/google/oauth2/id_token.py index e5dda508d..60db8aed0 100644 --- a/google/oauth2/id_token.py +++ b/google/oauth2/id_token.py @@ -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 @@ -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: