Skip to content

Commit

Permalink
refresh_access_token improved, remove refresh_or_register
Browse files Browse the repository at this point in the history
If no refresh token is found, now an exception are raised.
Removed refresh_or_register method for LoginAuthenticator and
FileAuthenticator. This method was useless in my eyes.
  • Loading branch information
mkb79 committed Jun 2, 2020
1 parent 5865d07 commit 673618d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/audible/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = 'audible'
__description__ = 'A(Sync) Interface for internal Audible API written in pure Python.'
__url__ = 'https://github.com/mkb79/audible'
__version__ = '0.3.0a0'
__version__ = '0.3.0a1'
__author__ = 'mkb79'
__author_email__ = '[email protected]'
__license__ = 'AGPL'
Expand Down
21 changes: 8 additions & 13 deletions src/audible/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .aescipher import AESCipher, detect_file_encryption
from .login import login
from .errors import NoAuthFlow
from .errors import NoAuthFlow, NoRefreshToken
from .register import deregister as deregister_
from .register import register as register_
from .utils import test_convert
Expand Down Expand Up @@ -245,7 +245,7 @@ def to_file(self, filename=None, password=None, encryption="default",
logger.info(f"set filename {filename} as default")

def re_login(self, username, password, captcha_callback=None,
otp_callback=None):
otp_callback=None, cvf_callback=None):

login_device = login(
username=username,
Expand All @@ -254,7 +254,8 @@ def re_login(self, username, password, captcha_callback=None,
domain = self.locale.domain,
marketPlaceId = self.locale.marketPlaceId,
captcha_callback=captcha_callback,
otp_callback=otp_callback
otp_callback=otp_callback,
cvf_callback=cvf_callback
)

self.update(**login_device)
Expand All @@ -272,6 +273,10 @@ def deregister_device(self, deregister_all: bool = False):

def refresh_access_token(self, force=False):
if force or self.access_token_expired:
if self.refresh_token is None:
message = "No refresh token found. Can't refresh access token."
logger.critical(message)
raise NoRefreshToken(message)
refresh_data = refresh_access_token(
refresh_token=self.refresh_token,
domain=self.locale.domain
Expand All @@ -282,16 +287,6 @@ def refresh_access_token(self, force=False):
logger.info("Access Token not expired. No refresh nessessary. "
"To force refresh please use force=True")

def refresh_or_register(self, force=False):
try:
self.refresh_access_token(force=force)
except:
try:
self.deregister_device()
self.register_device()
except:
raise Exception("Could not refresh client.")

def user_profile(self):
return user_profile(access_token=self.access_token,
domain=self.locale.domain)
Expand Down
5 changes: 5 additions & 0 deletions src/audible/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ class UnexpectedError(StatusError):
class NoAuthFlow(Exception):
"""Raised if no auth method available"""
pass


class NoRefreshToken(Exception):
"""Raised if refresh token is needed but not provided"""
pass

0 comments on commit 673618d

Please sign in to comment.