Commit 92d0c0ff authored by echel0n's avatar echel0n

Refactored offline tokens to be revoked before being replaced, resolves issues...

Refactored offline tokens to be revoked before being replaced, resolves issues with tokens piling up.
parent 6441d4ff
......@@ -46,7 +46,11 @@ class API(object):
@token.setter
@CacheDB.with_session
def token(self, value, session=None):
session.query(CacheDB.OAuth2Token).delete()
query = session.query(CacheDB.OAuth2Token)
if query.count():
token = query.first()
sickrage.app.oidc_client.logout(token.refresh_token)
query.delete()
if value:
session.add(CacheDB.OAuth2Token(**{
......@@ -61,6 +65,14 @@ class API(object):
def userinfo(self):
return self._request('GET', 'userinfo')
def refresh_token(self):
extra = {
'client_id': self.client_id,
'client_secret': self.client_secret
}
self.token = self.session.refresh_token(self.token_url, **extra)
def allowed_usernames(self):
return self._request('GET', 'allowed-usernames')
......@@ -85,12 +97,7 @@ class API(object):
except ValueError:
return resp.content
except TokenExpiredError as e:
extra = {
'client_id': self.client_id,
'client_secret': self.client_secret
}
self.token = self.session.refresh_token(self.token_url, **extra)
self.refresh_token()
except (InvalidClientIdError, MissingTokenError, InvalidGrantError) as e:
latest_exception = "Invalid token error, please re-authenticate by logging out then logging back in from web-ui"
break
......
......@@ -111,7 +111,7 @@ class GenericProvider(object):
resp = ProviderAPI().get_urls(self.id)
if resp and 'data' in resp:
return json.loads(resp['data']['urls'])
except (JSONDecodeError, APIError):
except (JSONDecodeError, APIError) as e:
pass
return self._urls
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment