From b2a8ddcd9370e8b11ebbc09dafbf216975c9b97a Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sun, 24 Mar 2019 16:20:52 +0100 Subject: [PATCH] OAuthManager: introduce username property --- picard/oauth.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/picard/oauth.py b/picard/oauth.py index fe3004c74..2dfeec6a9 100644 --- a/picard/oauth.py +++ b/picard/oauth.py @@ -98,11 +98,19 @@ class OAuthManager(object): else: config.persist["oauth_access_token_expires"] = value + @property + def username(self): + return config.persist["oauth_username"] + + @username.setter + def username(self, value): + config.persist["oauth_username"] = value + def is_authorized(self): return bool(self.refresh_token and self.refresh_token_scopes) def is_logged_in(self): - return self.is_authorized() and bool(config.persist["oauth_username"]) + return self.is_authorized() and bool(self.username) def revoke_tokens(self): # TODO actually revoke the tokens on MB (I think it's not implementented there) @@ -145,10 +153,6 @@ class OAuthManager(object): self.access_token = access_token self.access_token_expires = int(time.time() + expires_in - 60) - def set_username(self, username): - log.debug("OAuth: got username %s", username) - config.persist["oauth_username"] = username - def refresh_access_token(self, callback): log.debug("OAuth: refreshing access_token with a refresh_token %s", self.refresh_token) path = "/oauth2/token" @@ -226,7 +230,8 @@ class OAuthManager(object): if error: log.error("OAuth: username fetching failed: %s", data) else: - self.set_username(data["sub"]) + self.username = data["sub"] + log.debug("OAuth: got username %s", self.username) successful = True except Exception as e: log.error('OAuth: Unexpected error handling username fetch response: %r', e)