Implement oauth support

This commit is contained in:
werwolf2303
2025-06-10 21:43:03 +02:00
parent 322584bf43
commit f210850bee
2 changed files with 126 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ from Cryptodome.Protocol.KDF import PBKDF2
from Cryptodome.PublicKey import RSA
from Cryptodome.Signature import PKCS1_v1_5
from librespot import util
from librespot import util, oauth
from librespot import Version
from librespot.audio import AudioKeyManager
from librespot.audio import CdnManager
@@ -48,6 +48,7 @@ from librespot.metadata import EpisodeId
from librespot.metadata import PlaylistId
from librespot.metadata import ShowId
from librespot.metadata import TrackId
from librespot.oauth import OAuth
from librespot.proto import Authentication_pb2 as Authentication
from librespot.proto import ClientToken_pb2 as ClientToken
from librespot.proto import Connect_pb2 as Connect
@@ -1595,6 +1596,12 @@ class Session(Closeable, MessageListener, SubListener):
pass
return self
def oauth(self) -> Session.Builder:
if os.path.isfile(self.conf.stored_credentials_file):
return self.stored_file(None)
self.login_credentials = OAuth(MercuryRequests.keymaster_client_id, "http://127.0.0.1:5588/login").flow()
return self
def user_pass(self, username: str, password: str) -> Session.Builder:
"""Create credential from username and password