From 6a03d6dcd68053ec66d5589c5042a652920bc5dc Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sat, 28 Aug 2021 19:06:57 +0200 Subject: [PATCH] Remove deprecated/broken Facebook login The current approach is broken and there is no alternative yet, so remove it until there is another approach. See also: - https://github.com/librespot-org/librespot/discussions/635 - https://github.com/hrkfdn/ncspot/pull/537 Closes #310 --- src/authentication.rs | 74 +------------------------------------------ 1 file changed, 1 insertion(+), 73 deletions(-) diff --git a/src/authentication.rs b/src/authentication.rs index 2e0bf76..dcc5dcb 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -1,7 +1,7 @@ use cursive::traits::Boxable; use cursive::view::Identifiable; use cursive::views::*; -use cursive::{CbSink, Cursive, CursiveExt}; +use cursive::{Cursive, CursiveExt}; use librespot_core::authentication::Credentials as RespotCredentials; use librespot_protocol::authentication::AuthenticationType; @@ -49,26 +49,6 @@ pub fn create_credentials() -> Result { s.pop_layer(); s.add_layer(login_view); }) - .button("Login with Facebook", |s| { - let urls: std::collections::HashMap = - reqwest::blocking::get("https://login2.spotify.com/v1/config") - .expect("didn't connect") - .json() - .expect("didn't parse"); - // not a dialog to let people copy & paste the URL - let url_notice = TextView::new(format!("Browse to {}", &urls["login_url"])); - - let controls = Button::new("Quit", Cursive::quit); - - let login_view = LinearLayout::new(cursive::direction::Orientation::Vertical) - .child(url_notice) - .child(controls); - let url = &urls["login_url"]; - webbrowser::open(url).ok(); - auth_poller(&urls["credentials_url"], s.cb_sink()); - s.pop_layer(); - s.add_layer(login_view) - }) .button("Quit", Cursive::quit); login_cursive.add_layer(info_view); @@ -80,58 +60,6 @@ pub fn create_credentials() -> Result { .unwrap_or_else(|| Err("Didn't obtain any credentials".to_string())) } -// TODO: better with futures? -fn auth_poller(url: &str, app_sink: &CbSink) { - let app_sink = app_sink.clone(); - let url = url.to_string(); - std::thread::spawn(move || { - let timeout = std::time::Duration::from_secs(5 * 60); - let start_time = std::time::SystemTime::now(); - while std::time::SystemTime::now() - .duration_since(start_time) - .unwrap_or(timeout) - < timeout - { - if let Ok(response) = reqwest::blocking::get(&url) { - if response.status() != reqwest::StatusCode::ACCEPTED { - let result = match response.status() { - reqwest::StatusCode::OK => { - let creds = response - .json::() - .expect("Unable to parse") - .credentials; - Ok(creds) - } - - _ => Err(format!( - "Facebook auth failed with code {}: {}", - response.status(), - response.text().unwrap() - )), - }; - app_sink - .send(Box::new(|s: &mut Cursive| { - s.set_user_data(result); - s.quit(); - })) - .unwrap(); - return; - } - } - std::thread::sleep(std::time::Duration::from_millis(1000)); - } - - app_sink - .send(Box::new(|s: &mut Cursive| { - s.set_user_data::>(Err( - "Timed out authenticating".to_string(), - )); - s.quit(); - })) - .unwrap(); - }); -} - #[derive(Serialize, Deserialize, Debug)] pub struct AuthResponse { pub credentials: RespotCredentials,