aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2020-04-12 08:54:50 +0200
committerneodarz <neodarz@neodarz.net>2020-04-12 08:54:50 +0200
commit92528fe0387dddaf19ba562fe98bf073c8a756c9 (patch)
treebbfcc048fdc1f47787aad086ad2f4ae01ee7fb2d
parent17bce3c89c6d991690d6a56d28afcdb22c969200 (diff)
downloadpyfunkwhale-92528fe0387dddaf19ba562fe98bf073c8a756c9.tar.xz
pyfunkwhale-92528fe0387dddaf19ba562fe98bf073c8a756c9.zip
Re ask token if scope is invalid
-rw-r--r--pyfunkwhale/client.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pyfunkwhale/client.py b/pyfunkwhale/client.py
index c905c57..1fce019 100644
--- a/pyfunkwhale/client.py
+++ b/pyfunkwhale/client.py
@@ -5,6 +5,7 @@ import json
import re
from time import time
from requests_oauthlib import OAuth2Session
+from oauthlib.oauth2.rfc6749.errors import InvalidScopeError
from requests.models import Response
from pyfunkwhale.utils import read_file, write_file
@@ -65,11 +66,14 @@ class Client(object):
token from the instance.
"""
if time() - 60 > self.token["expires_at"]:
- self.token = self.oauth_client.refresh_token(
- self.token_endpoint,
- refresh_token=self.token["refresh_token"],
- client_id=self.client_id,
- client_secret=self.client_secret)
+ try:
+ self.token = self.oauth_client.refresh_token(
+ self.token_endpoint,
+ refresh_token=self.token["refresh_token"],
+ client_id=self.client_id,
+ client_secret=self.client_secret)
+ except InvalidScopeError:
+ self._get_token()
write_file(self.token_filename, self.token)
def call(self, endpoint: str, method: str, params: dict = None,