Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the old python3-google-auth in Debian (1.5.x) #276

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lieer/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import json
import os
import time

Expand Down Expand Up @@ -506,8 +507,23 @@ def __store_credentials__(self, path, credentials):
"""
Store valid credentials in json format
"""
with open(path, "w") as storage:
storage.write(credentials.to_json())
with open(path + ".new", "w") as storage:
try:
storage.write(credentials.to_json())
except AttributeError:
storage.write(
json.dumps(
{
"token": credentials.token,
"refresh_token": credentials.refresh_token,
"token_uri": credentials.token_uri,
"client_id": credentials.client_id,
"client_secret": credentials.client_secret,
"scopes": credentials.scopes,
}
)
)
os.rename(path + ".new", path)

def __get_credentials__(self):
"""
Expand All @@ -528,7 +544,11 @@ def __get_credentials__(self):
)

if not credentials or not credentials.valid:
if credentials and credentials.expired and credentials.refresh_token:
if (
credentials
and (credentials.expired or not credentials.token)
and credentials.refresh_token
):
credentials.refresh(Request())

elif self.CLIENT_SECRET_FILE is not None:
Expand Down
Loading