diff --git a/docs/authentication.md b/docs/authentication.md index eae8e927..86470161 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -64,7 +64,7 @@ in their browser, where CSRF is a random token, and PORT is the HTTPS server's p This will redirect to Facebook, where the user must login and authorize Spotify, and finally make a GET request to `https://login.spotilocal.com:PORT/login/facebook_login_sso.json?csrf=CSRF&access_token=TOKEN`, -where CSRF is the same string sent earlier, and TOKEN is the facebook authentication token. +where PORT and CSRF are the same as sent earlier, and TOKEN is the facebook authentication token. Since `login.spotilocal.com` resolves the 127.0.0.1, the request is received by the client. diff --git a/src/facebook.rs b/src/facebook.rs index 9523a61c..d99557fd 100644 --- a/src/facebook.rs +++ b/src/facebook.rs @@ -1,5 +1,6 @@ use hyper; use hyper::net::Openssl; +use hyper::net::NetworkListener; use hyper::server::Request; use hyper::server::Response; use hyper::uri::RequestUri; @@ -93,12 +94,15 @@ pub fn facebook_login() -> Result { }; let ssl = spotilocal_ssl_context().unwrap(); - let mut server = hyper::Server::https("127.0.0.1:8001", ssl).unwrap().handle(handler).unwrap(); + + let mut listener = hyper::net::HttpsListener::new("127.0.0.1:0", ssl).unwrap(); + let port = listener.local_addr().unwrap().port(); + + let mut server = hyper::Server::new(listener).handle(handler).unwrap(); println!("Logging in using Facebook, please visit https://login.spotify.com/login-facebook-sso/?csrf={}&port={} in your browser.", - csrf, 8001); + csrf, port); - //a2c27234068bbe05d22c1b930b3bc2f5 let token = rx.recv().unwrap(); let user_id = facebook_get_me_id(&token).unwrap(); let cred = Credentials {