diff --git a/Cargo.lock b/Cargo.lock index 1843a3d..921148a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1392,6 +1392,7 @@ version = "0.7.1" dependencies = [ "ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_migrations 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index f381b25..f90ad58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ ui = [] [dependencies] ape = "0.2.0" app_dirs = "1.1.1" +base64 = "0.9.3" diesel = { version = "1.3.3", features = ["sqlite"] } diesel_migrations = { version = "1.3.0", features = ["sqlite"] } error-chain = "0.12.0" diff --git a/src/api.rs b/src/api.rs index e8062be..845ade4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,5 +1,7 @@ +use base64; use diesel::prelude::*; use iron::headers::{Authorization, Basic, Range}; +use iron::mime::Mime; use iron::prelude::*; use iron::{status, AroundMiddleware, Handler}; use mount::Mount; @@ -726,7 +728,24 @@ fn lastfm_auth(request: &mut Request, db: &DB) -> IronResult { lastfm::auth(db, &username, &token)?; - Ok(Response::with(status::Ok)) + let url_encoded_content = match input.find(&["content"]) { + Some(¶ms::Value::String(ref content)) => content.clone(), + _ => return Err(Error::from(ErrorKind::MissingDesiredResponse).into()), + }; + + let base64_content = match percent_decode(url_encoded_content.as_bytes()).decode_utf8() { + Ok(s) => s, + Err(_) => return Err(Error::from(ErrorKind::EncodingError).into()), + }; + + let popup_content = match base64::decode(base64_content.as_bytes()) { + Ok(c) => c, + Err(_) => return Err(Error::from(ErrorKind::EncodingError).into()), + }; + + let mime = "text/html".parse::().unwrap(); + + Ok(Response::with((mime, status::Ok, popup_content))) } fn lastfm_now_playing(request: &mut Request, db: &DB) -> IronResult { diff --git a/src/errors.rs b/src/errors.rs index 1243176..18f453e 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -56,6 +56,7 @@ error_chain! { MissingLastFMCredentials {} LastFMAuthError {} LastFMDeserializationError {} + MissingDesiredResponse {} } } diff --git a/src/main.rs b/src/main.rs index 46cd092..f3d6366 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ extern crate ape; extern crate app_dirs; +extern crate base64; extern crate core; extern crate crypto; #[macro_use]