|
25 | 25 |
|
26 | 26 | from google.auth import environment_vars |
27 | 27 | from google.auth import exceptions |
| 28 | +from google.auth import constraints |
28 | 29 | import google.auth.transport._http_client |
29 | 30 |
|
30 | 31 | _LOGGER = logging.getLogger(__name__) |
@@ -127,9 +128,13 @@ def load_credentials_from_file( |
127 | 128 | filename, info, scopes, default_scopes, quota_project_id, request |
128 | 129 | ) |
129 | 130 |
|
130 | | - |
131 | 131 | def load_credentials_from_dict( |
132 | 132 | info, scopes=None, default_scopes=None, quota_project_id=None, request=None |
| 133 | +): |
| 134 | + return load_credentials_from_dict_with_constraints(info, constraints.Constraints(allow_types="all"), scopes, default_scopes, quota_project_id, request) |
| 135 | + |
| 136 | +def load_credentials_from_dict_with_constraints( |
| 137 | + info, constraints, scopes=None, default_scopes=None, quota_project_id=None, request=None |
133 | 138 | ): |
134 | 139 | """Loads Google credentials from a dict. |
135 | 140 |
|
@@ -173,12 +178,15 @@ def load_credentials_from_dict( |
173 | 178 |
|
174 | 179 |
|
175 | 180 | def _load_credentials_from_info( |
176 | | - filename, info, scopes, default_scopes, quota_project_id, request |
| 181 | + filename, info, scopes, default_scopes, quota_project_id, request, constraints |
177 | 182 | ): |
178 | 183 | from google.auth.credentials import CredentialsWithQuotaProject |
179 | 184 |
|
180 | 185 | credential_type = info.get("type") |
181 | 186 |
|
| 187 | + if constraints.isValid(info) is False: |
| 188 | + raise exceptions.InvalidType(f"{credential_type} is not allowed as per provided constraints or is not a valid credential type") |
| 189 | + |
182 | 190 | if credential_type == _AUTHORIZED_USER_TYPE: |
183 | 191 | credentials, project_id = _get_authorized_user_credentials( |
184 | 192 | filename, info, scopes |
|
0 commit comments