If a valid access token is in memory, returns it Else fetches a new token and returns it Parameters: - as_dict: (deprecated) a boolean indicating if returning the access token as a token_info dictionary, otherwise it will be returned
(self, as_dict=True, check_cache=True)
| 182 | self.cache_handler = CacheFileHandler() |
| 183 | |
| 184 | def get_access_token(self, as_dict=True, check_cache=True): |
| 185 | """ |
| 186 | If a valid access token is in memory, returns it |
| 187 | Else fetches a new token and returns it |
| 188 | |
| 189 | Parameters: |
| 190 | - as_dict: (deprecated) a boolean indicating if returning the access token |
| 191 | as a token_info dictionary, otherwise it will be returned |
| 192 | as a string. |
| 193 | """ |
| 194 | if as_dict: |
| 195 | warnings.warn( |
| 196 | "You're using 'as_dict = True'." |
| 197 | "get_access_token will return the token string directly in future " |
| 198 | "versions. Please adjust your code accordingly, or use " |
| 199 | "get_cached_token instead.", |
| 200 | DeprecationWarning, |
| 201 | stacklevel=2, |
| 202 | ) |
| 203 | |
| 204 | if check_cache: |
| 205 | token_info = self.cache_handler.get_cached_token() |
| 206 | if token_info and not self.is_token_expired(token_info): |
| 207 | return token_info if as_dict else token_info["access_token"] |
| 208 | |
| 209 | token_info = self._request_access_token() |
| 210 | token_info = self._add_custom_values_to_token_info(token_info) |
| 211 | self.cache_handler.save_token_to_cache(token_info) |
| 212 | return token_info if as_dict else token_info["access_token"] |
| 213 | |
| 214 | def _request_access_token(self): |
| 215 | """Gets client credentials access token """ |