1616
1717from __future__ import annotations
1818
19- import threading
2019from typing import Literal , Optional , Sequence , Tuple
2120import warnings
2221
2322import google .auth .credentials
24- import google .auth .transport .requests
2523import requests .adapters
2624
2725import bigframes ._config .auth
@@ -101,7 +99,6 @@ def __init__(
10199 ] = (),
102100 enable_polars_execution : bool = False ,
103101 ):
104- self ._credentials_and_project_lock = threading .Lock ()
105102 self ._credentials = credentials
106103 self ._project = project
107104 self ._location = _get_validated_location (location )
@@ -149,27 +146,23 @@ def application_name(self, value: Optional[str]):
149146 def _try_set_default_credentials_and_project (
150147 self ,
151148 ) -> tuple [google .auth .credentials .Credentials , Optional [str ]]:
152- with self ._credentials_and_project_lock :
153- # Don't fetch credentials or project if credentials is already set.
154- # If it's set, we've already authenticated, so if the user wants to
155- # re-auth, they should explicitly reset the credentials.
156- if self ._credentials is not None :
157- return self ._credentials , self ._project
158-
159- (
160- credentials ,
161- credentials_project ,
162- ) = bigframes ._config .auth .get_default_credentials_with_project ()
163-
164- # Ensure an access token is available.
165- credentials .refresh (google .auth .transport .requests .Request ())
166- self ._credentials = credentials
149+ # Don't fetch credentials or project if credentials is already set.
150+ # If it's set, we've already authenticated, so if the user wants to
151+ # re-auth, they should explicitly reset the credentials.
152+ if self ._credentials is not None :
153+ return self ._credentials , self ._project
154+
155+ (
156+ credentials ,
157+ credentials_project ,
158+ ) = bigframes ._config .auth .get_default_credentials_with_project ()
159+ self ._credentials = credentials
167160
168- # Avoid overriding an explicitly set project with a default value.
169- if self ._project is None :
170- self ._project = credentials_project
161+ # Avoid overriding an explicitly set project with a default value.
162+ if self ._project is None :
163+ self ._project = credentials_project
171164
172- return credentials , credentials_project
165+ return credentials , self . _project
173166
174167 @property
175168 def credentials (self ) -> google .auth .credentials .Credentials :
@@ -191,6 +184,11 @@ def credentials(self) -> google.auth.credentials.Credentials:
191184 def credentials (self , value : Optional [google .auth .credentials .Credentials ]):
192185 if self ._session_started and self ._credentials is not value :
193186 raise ValueError (SESSION_STARTED_MESSAGE .format (attribute = "credentials" ))
187+
188+ if value is None :
189+ # The user has _explicitly_ asked that we re-authenticate.
190+ bigframes ._config .auth .reset_default_credentials_and_project ()
191+
194192 self ._credentials = value
195193
196194 @property
0 commit comments