mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 12:15:13 +03:00
✨ add refreshToken
This commit is contained in:
+1
-1
@@ -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
@@ -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()
|
||||
|
||||
@@ -8,6 +8,7 @@ class Settings(TypedDict, total=False):
|
||||
|
||||
class ConfigData(TypedDict, total=False):
|
||||
token: str
|
||||
refresh_token: str
|
||||
settings: Settings
|
||||
|
||||
|
||||
|
||||
+7
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user