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

Moved LinkLogin and futures to login_oauth. #303

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,10 @@ def login_oauth(self) -> Tuple[LinkLogin, concurrent.futures.Future[Any]]:
a :class:`concurrent.futures.Future` that will poll until the login is completed, or until the link expires.
:raises: TimeoutError: If the login takes too long
"""
login, future = self._login_with_link()
return login, future
json_obj: JsonObj = self._login_with_link()
executor = concurrent.futures.ThreadPoolExecutor()

return LinkLogin(json_obj), executor.submit(self._process_link_login, json_obj)

def save_session_to_file(self, session_file: Path):
# create a new session
Expand Down Expand Up @@ -644,7 +646,7 @@ def load_session_from_file(self, session_file: Path):

return self.load_oauth_session(**args)

def _login_with_link(self) -> Tuple[LinkLogin, concurrent.futures.Future[Any]]:
def _login_with_link(self) -> JsonObj:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should not be a private method if 3rd party libs plan to access it directly. I also suggest adding doxygen for the same reason as above.

It should also be renamed, since its purpose will have changed significantly. Perhaps something like oauth_request_device_auth()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are totally right. Excuse me this sloppy PR. I will do a proper refactoring and re-submit this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem at all :)

url = "https://auth.tidal.com/v1/oauth2/device_authorization"
params = {"client_id": self.config.client_id, "scope": "r_usr w_usr w_sub"}

Expand All @@ -655,8 +657,8 @@ def _login_with_link(self) -> Tuple[LinkLogin, concurrent.futures.Future[Any]]:
request.raise_for_status()

json = request.json()
executor = concurrent.futures.ThreadPoolExecutor()
return LinkLogin(json), executor.submit(self._process_link_login, json)

return json

def _process_link_login(self, json: JsonObj) -> None:
json = self._wait_for_link_login(json)
Expand Down
Loading