@@ -130,6 +130,50 @@ def load_credentials_from_file(
130130 )
131131
132132
133+ def load_credentials_from_dict (
134+ info , scopes = None , default_scopes = None , quota_project_id = None , request = None
135+ ):
136+ """Loads Google credentials from a dict.
137+
138+ The credentials file must be a service account key, stored authorized
139+ user credentials, external account credentials, or impersonated service
140+ account credentials.
141+
142+ Args:
143+ info (Dict[str, Any]): A dict object containing the credentials
144+ scopes (Optional[Sequence[str]]): The list of scopes for the credentials. If
145+ specified, the credentials will automatically be scoped if
146+ necessary
147+ default_scopes (Optional[Sequence[str]]): Default scopes passed by a
148+ Google client library. Use 'scopes' for user-defined scopes.
149+ quota_project_id (Optional[str]): The project ID used for
150+ quota and billing.
151+ request (Optional[google.auth.transport.Request]): An object used to make
152+ HTTP requests. This is used to determine the associated project ID
153+ for a workload identity pool resource (external account credentials).
154+ If not specified, then it will use a
155+ google.auth.transport.requests.Request client to make requests.
156+
157+ Returns:
158+ Tuple[google.auth.credentials.Credentials, Optional[str]]: Loaded
159+ credentials and the project ID. Authorized user credentials do not
160+ have the project ID information. External account credentials project
161+ IDs may not always be determined.
162+
163+ Raises:
164+ google.auth.exceptions.DefaultCredentialsError: if the file is in the
165+ wrong format or is missing.
166+ """
167+ if not isinstance (info , dict ):
168+ raise exceptions .DefaultCredentialsError (
169+ "info object was of type {} but dict type was expected." .format (type (info ))
170+ )
171+
172+ return _load_credentials_from_info (
173+ "dict object" , info , scopes , default_scopes , quota_project_id , request
174+ )
175+
176+
133177def _load_credentials_from_info (
134178 filename , info , scopes , default_scopes , quota_project_id , request
135179):
0 commit comments