Lines Matching full:credentials
21 import google.auth.credentials
42 """Returns credentials loaded from a file."""
44 …credentials, _ = google.auth.load_credentials_from_file(filename, scopes=scopes, quota_project_id=…
45 return credentials
52 """Returns Application Default Credentials."""
54 credentials, _ = google.auth.default(scopes=scopes, quota_project_id=quota_project_id)
55 return credentials
70 def with_scopes(credentials, scopes): argument
71 """Scopes the credentials if necessary.
74 credentials (Union[
75 google.auth.credentials.Credentials,
76 oauth2client.client.Credentials]): The credentials to scope.
80 Union[google.auth.credentials.Credentials,
81 oauth2client.client.Credentials]: The scoped credentials.
83 if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
84 return google.auth.credentials.with_scopes_if_required(credentials, scopes)
87 if credentials.create_scoped_required():
88 return credentials.create_scoped(scopes)
90 return credentials
92 return credentials
95 def authorized_http(credentials): argument
96 """Returns an http client that is authorized with the given credentials.
99 credentials (Union[
100 google.auth.credentials.Credentials,
101 oauth2client.client.Credentials]): The credentials to use.
109 if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
112 "Credentials from google.auth specified, but "
113 "google-api-python-client is unable to use these credentials "
117 return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http())
119 return credentials.authorize(build_http())
122 def refresh_credentials(credentials): argument
124 # credentials could be a AuthorizedHttp or an oauth2client-decorated
128 if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
130 return credentials.refresh(request)
132 return credentials.refresh(refresh_http)
135 def apply_credentials(credentials, headers): argument
137 if not is_valid(credentials):
138 refresh_credentials(credentials)
139 return credentials.apply(headers)
142 def is_valid(credentials): argument
143 if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
144 return credentials.valid
147 credentials.access_token is not None
148 and not credentials.access_token_expired
155 elif hasattr(http.request, "credentials"):
156 return http.request.credentials
157 elif hasattr(http, "credentials") and not isinstance(
158 http.credentials, httplib2.Credentials
160 return http.credentials