1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-06 03:50:06 +02:00

Move keymaster to core

This commit is contained in:
Sasha Hilton 2018-02-06 19:54:28 +01:00
parent 578d6b7f06
commit 6a442a4570
5 changed files with 38 additions and 6 deletions

26
core/src/keymaster.rs Normal file
View file

@ -0,0 +1,26 @@
use futures::Future;
use serde_json;
use mercury::MercuryError;
use session::Session;
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Token {
pub access_token: String,
pub expires_in: u32,
pub token_type: String,
pub scope: Vec<String>,
}
pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> {
let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}",
client_id, scopes);
Box::new(session.mercury().get(url).map(move |response| {
let data = response.payload.first().expect("Empty payload");
let data = String::from_utf8(data.clone()).unwrap();
let token : Token = serde_json::from_str(&data).unwrap();
token
}))
}