/// Authenticate on the remote device thanks to the encrypted blob
Authenticate on the remote device thanks to the encrypted blob
Authenticate on the remote device thanks to the encrypted blob
pub fn add_user(
    base_url: &str,
    username: &str,
    blob: &str,
    my_public_key: &str,
    token_type: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
    let device_id = hex::encode(Sha1::digest("spotify-connect".as_bytes()));
    let login_id = hex::encode(rand::thread_rng().gen::<[u8; 16]>());
    let mut request = minreq::post(base_url)
        .with_header("Content-Type", "application/x-www-form-urlencoded")
        .with_param("action", "addUser")
        .with_param("userName", username)
        .with_param("blob", blob)
        .with_param("clientKey", my_public_key)
        .with_param("deviceId", device_id)
        .with_param("deviceName", "spotify-connect")
        .with_param("loginId", login_id);
    if let Some(token_type) = token_type {
        request = request.with_param("tokenType", token_type);
    }
    let response = request.send()?;
    let v: Value = serde_json::from_str(response.as_str()?)?;
    match v["statusString"].as_str() {
        Some("ERROR-OK") | Some("OK") => Ok(()),
        _ => Err(v.to_string().into()),
    }
}
pub fn add_user ( base_url : & str , username : & str , blob : & str , my_public_key : & str , token_type : Option < & str > , ) -> Result < ( ) , Box < dyn std :: error :: Error > > { let device_id = hex :: encode ( Sha1 :: digest ( " " . as_bytes ( ) ) ) ; let login_id = hex :: encode ( rand :: thread_rng ( ) . gen :: < [ u8 ; 16 ] > ( ) ) ; let mut request = minreq :: post ( base_url ) . with_header ( " " , " " ) . with_param ( " " , " " ) . with_param ( " " , username ) . with_param ( " " , blob ) . with_param ( " " , my_public_key ) . with_param ( " " , device_id ) . with_param ( " " , " " ) . with_param ( " " , login_id ) ; if let Some ( token_type ) = token_type { request = request . with_param ( " " , token_type ) ; } let response = request . send ( ) ? ; let v : Value = serde_json :: from_str ( response . as_str ( ) ? ) ? ; match v [ " " ] . as_str ( ) { Some ( " " ) | Some ( " " ) => Ok ( ( ) ) , _ => Err ( v . to_string ( ) . into ( ) ) , } }
Authenticate on the remote device thanks to the encrypted blob
Authenticate on the remote device thanks to the encrypted blob
base_url
&str
username
&str
blob
&str
my_public_key
&str
token_type
Option<&str>