Skip to content

Commit

Permalink
Check if credentials have changed beteween config and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
anxuae committed Apr 27, 2022
1 parent 0e46dbc commit ba0df2d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pibooth_google_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _get_authorized_session(self):
if not os.path.exists(self.token_cache_file) or \
os.path.getsize(self.token_cache_file) == 0:
credentials = self._auth()
LOGGER.debug("First use of pibooth-google-photo: store token in file %s",
LOGGER.debug("First use of plugin, store token in file '%s'",
self.token_cache_file)
try:
self._save_credentials(credentials)
Expand All @@ -130,7 +130,14 @@ def _get_authorized_session(self):
self.token_cache_file, err)
else:
credentials = Credentials.from_authorized_user_file(self.token_cache_file, self.SCOPES)
if credentials.expired:
with open(self.client_id_file) as fd:
data = json.load(fd)
if credentials.client_id != data.get('client_id') or\
credentials.client_secret != data.get('client_secret'):
LOGGER.debug("Application key or secret has changed, store new token in file '%s'",
self.token_cache_file)
credentials = self._auth()
elif credentials.expired:
credentials.refresh(Request())
self._save_credentials(credentials)

Expand Down

0 comments on commit ba0df2d

Please sign in to comment.