Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ae25f47
fix: add types to verify_token and request __init__
wyattscarpenter Aug 20, 2024
fef7572
Merge branch 'main' into patch-1
wyattscarpenter Aug 5, 2025
bfd3dee
type default based on comments
wyattscarpenter Aug 6, 2025
e93ddd1
Update _default.py: wait actually I do want it to be Noneable, that's…
wyattscarpenter Aug 6, 2025
72e40a9
Update _default.py: it's probably better to use the more-supported sy…
wyattscarpenter Aug 6, 2025
6ab82cd
Update _default.py: attempt to avoid circular import
wyattscarpenter Aug 6, 2025
f96c2a5
Merge branch 'main' into patch-1
chalmerlowe Dec 22, 2025
64ae612
Merge branch 'main' into patch-1
chalmerlowe Dec 23, 2025
e867a0b
Merge branch 'main' into patch-1
chalmerlowe Dec 23, 2025
5e7e3f5
Update google/auth/_default.py
chalmerlowe Dec 23, 2025
45306de
Update google/auth/_default.py
chalmerlowe Dec 23, 2025
2e6829e
Update google/auth/_default.py
chalmerlowe Dec 23, 2025
448d752
Update google/auth/_default.py
chalmerlowe Dec 23, 2025
f4540e3
Update google/oauth2/id_token.py
chalmerlowe Dec 23, 2025
0a99a32
Update google/oauth2/id_token.py
chalmerlowe Dec 23, 2025
ae81aff
Update google/oauth2/id_token.py
chalmerlowe Dec 23, 2025
be19889
Update google/auth/transport/requests.py
chalmerlowe Dec 23, 2025
7bf82e8
Update google/auth/transport/requests.py
chalmerlowe Dec 23, 2025
58d8a88
Update google/auth/transport/requests.py
chalmerlowe Dec 23, 2025
958292a
Update google/auth/transport/requests.py
chalmerlowe Dec 23, 2025
fa336fd
Merge branch 'main' into patch-1
chalmerlowe Dec 23, 2025
4be0692
Update _default.py
chalmerlowe Dec 23, 2025
152bc0e
Update id_token.py
chalmerlowe Dec 23, 2025
f5ca5e4
Update _default.py
chalmerlowe Dec 23, 2025
6d75ce2
Apply suggestion from @chalmerlowe
chalmerlowe Dec 23, 2025
82f1422
Apply suggestion from @chalmerlowe
chalmerlowe Dec 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
Implements application default credentials and project ID detection.
"""

from collections.abc import Sequence
import io
import json
import logging
import os
from typing import Optional, TYPE_CHECKING
import warnings

from google.auth import environment_vars
from google.auth import exceptions

if TYPE_CHECKING: # pragma: NO COVER
# flake8 raises an error because these lines are not used in the code,
# they are only used for type-hinting, hence the F401 pragma.
from google.auth.credentials import Credentials # noqa: F401
from google.auth.transport import Request # noqa: F401
import google.auth.transport._http_client

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -588,7 +596,12 @@ def _apply_quota_project_id(credentials, quota_project_id):
return credentials


def default(scopes=None, request=None, quota_project_id=None, default_scopes=None):
def default(
scopes: Optional[Sequence[str]] = None,
request: Optional["google.auth.transport.Request"] = None,
quota_project_id: Optional[str] = None,
default_scopes: Optional[Sequence[str]] = None,
) -> tuple["google.auth.credentials.Credentials", Optional[str]]:
"""Gets the default credentials for the current environment.

`Application Default Credentials`_ provides an easy way to obtain
Expand Down
3 changes: 2 additions & 1 deletion google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import logging
import numbers
import time
from typing import Optional

try:
import requests
Expand Down Expand Up @@ -137,7 +138,7 @@ class Request(transport.Request):
.. automethod:: __call__
"""

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

Expand Down
14 changes: 8 additions & 6 deletions google/oauth2/id_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@
import http.client as http_client
import json
import os
from typing import Any, Mapping, Union

from google.auth import environment_vars
from google.auth import exceptions
from google.auth import jwt
from google.auth import transport


# The URL that provides public certificates for verifying ID tokens issued
Expand Down Expand Up @@ -105,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: Union[str, list[str], None] = None,
certs_url: str = _GOOGLE_OAUTH2_CERTS_URL,
clock_skew_in_seconds: int = 0,
) -> Mapping[str, Any]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually bad to return something with Any in it, but, um, that's just what was in the comment. ¯\_(ツ)_/¯

If the reviewer happens to have a better & more-accurate idea, let him change this line accordingly.

"""Verifies an ID token and returns the decoded token.

Args:
Expand Down
Loading