add refreshToken

This commit is contained in:
oskvr37
2024-07-22 14:15:18 +02:00
parent 06bb318567
commit a7774e9106
4 changed files with 25 additions and 5 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ def main():
input("Hit enter when you are ready")
token = getToken(auth["deviceCode"])
print(token)
config.update({"token": token["access_token"]})
config.update({"token": token["access_token"], "refresh_token": token["refresh_token"]})
else:
print(config)
+16 -2
View File
@@ -1,5 +1,5 @@
from requests import request
from .types import DeviceAuthData, AuthData
from .types import DeviceAuthData, AuthResponse, AuthResponseWithRefresh
AUTH_URL = "https://auth.tidal.com/v1/oauth2"
CLIENT_ID = "7m7Ap0JC9j1cOM3n"
@@ -14,7 +14,7 @@ def getDeviceAuth() -> DeviceAuthData:
).json()
def getToken(device_code: str) -> AuthData:
def getToken(device_code: str) -> AuthResponseWithRefresh:
return request(
"POST",
f"{AUTH_URL}/token",
@@ -26,3 +26,17 @@ def getToken(device_code: str) -> AuthData:
},
auth=(CLIENT_ID, CLIENT_SECRET),
).json()
def refreshToken(refresh_token: str) -> AuthResponse:
return request(
"POST",
f"{AUTH_URL}/token",
data={
"client_id": CLIENT_ID,
"refresh_token": refresh_token,
"grant_type": "refresh_token",
"scope": "r_usr+w_usr+w_sub",
},
auth=(CLIENT_ID, CLIENT_SECRET),
).json()
+1
View File
@@ -8,6 +8,7 @@ class Settings(TypedDict, total=False):
class ConfigData(TypedDict, total=False):
token: str
refresh_token: str
settings: Settings
+7 -2
View File
@@ -38,22 +38,27 @@ class User(TypedDict):
newUser: bool
class AuthData(TypedDict):
class AuthResponse(TypedDict):
scope: str
user: User
clientName: str
token_type: str
access_token: str
refresh_token: str
expires_in: int
user_id: int
class AuthResponseWithRefresh(AuthResponse):
refresh_token: str
class Client(TypedDict):
id: int
name: str
authorizedForOffline: bool
authorizedForOfflineDate: Optional[str]
class SessionData(TypedDict):
sessionId: str
userId: int