Skip to content

Commit

Permalink
Remove deprecated username/pass login method (Fixes #279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehkillerbee committed Sep 11, 2024
1 parent 156836d commit 38777e0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
7 changes: 0 additions & 7 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def test_load_oauth_session(session):
assert isinstance(session.user, tidalapi.LoggedInUser)


def test_failed_login():
session = tidalapi.Session()
with pytest.raises(requests.HTTPError):
session.login("", "")
assert session.check_login() is False


@pytest.mark.interactive
def test_oauth_login(capsys):
config = tidalapi.Config(item_limit=20000)
Expand Down
30 changes: 1 addition & 29 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import datetime
import hashlib
import json
import locale
import logging
import os
import random
Expand All @@ -46,14 +45,13 @@
cast,
no_type_check,
)
from urllib.parse import parse_qs, urlencode, urljoin, urlsplit
from urllib.parse import parse_qs, urlencode, urlsplit

import requests
from requests.exceptions import HTTPError

from tidalapi.exceptions import *
from tidalapi.types import JsonObj

from . import album, artist, genre, media, mix, page, playlist, request, user

if TYPE_CHECKING:
Expand Down Expand Up @@ -416,32 +414,6 @@ def load_oauth_session(

return True

def login(self, username: str, password: str) -> bool:
"""Logs in to the TIDAL api.
:param username: The TIDAL username
:param password: The password to your TIDAL account
:return: Returns true if we think the login was successful.
"""
url = urljoin(self.config.api_v1_location, "login/username")
headers: dict[str, str] = {"X-Tidal-Token": self.config.api_token}
payload = {
"username": username,
"password": password,
"clientUniqueKey": format(random.getrandbits(64), "02x"),
}
request = self.request_session.post(url, data=payload, headers=headers)

if not request.ok:
log.error("Login failed: %s", request.text)
request.raise_for_status()

body = request.json()
self.session_id = str(body["sessionId"])
self.country_code = str(body["countryCode"])
self.user = user.User(self, user_id=body["userId"]).factory()
return True

def login_session_file(
self,
session_file: Path,
Expand Down

0 comments on commit 38777e0

Please sign in to comment.