1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-05 10:49:40 +02:00

Fix client-token and implement expiry logic

This commit is contained in:
Roderick van Domburg 2022-01-23 00:26:52 +01:00
parent 1528292583
commit 4ea1b77c7b
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
2 changed files with 57 additions and 23 deletions

View file

@ -93,7 +93,7 @@ impl TokenProvider {
let request = self.session().mercury().get(query_uri)?;
let response = request.await?;
let data = response.payload.first().ok_or(TokenError::Empty)?.to_vec();
let token = Token::new(String::from_utf8(data)?)?;
let token = Token::from_json(String::from_utf8(data)?)?;
trace!("Got token: {:#?}", token);
self.lock(|inner| inner.tokens.push(token.clone()));
Ok(token)
@ -103,7 +103,7 @@ impl TokenProvider {
impl Token {
const EXPIRY_THRESHOLD: Duration = Duration::from_secs(10);
pub fn new(body: String) -> Result<Self, Error> {
pub fn from_json(body: String) -> Result<Self, Error> {
let data: TokenData = serde_json::from_slice(body.as_ref())?;
Ok(Self {
access_token: data.access_token,