diff --git a/CHANGELOG.md b/CHANGELOG.md index c515a0f9..8bef11c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [playback] Changed type alias `MixerFn` to return `Result, Error>` instead of `Arc` (breaking) - [playback] Optimize audio conversion to always dither at 16-bit level, and improve performance - [playback] Normalizer maintains better stereo imaging, while also being faster +- [oauth] Remove loopback address requirement from `redirect_uri` when spawning callback handling server versus using stdin. ### Added diff --git a/oauth/src/lib.rs b/oauth/src/lib.rs index 1030722b..dca85528 100644 --- a/oauth/src/lib.rs +++ b/oauth/src/lib.rs @@ -187,24 +187,17 @@ fn get_authcode_listener( code } -// If the specified `redirect_uri` is HTTP, loopback, and contains a port, +// If the specified `redirect_uri` is HTTP and contains a port, // then the corresponding socket address is returned. fn get_socket_address(redirect_uri: &str) -> Option { - #![warn(missing_docs)] let url = match Url::parse(redirect_uri) { Ok(u) if u.scheme() == "http" && u.port().is_some() => u, _ => return None, }; - let socket_addr = match url.socket_addrs(|| None) { + match url.socket_addrs(|| None) { Ok(mut addrs) => addrs.pop(), _ => None, - }; - if let Some(s) = socket_addr { - if s.ip().is_loopback() { - return socket_addr; - } } - None } /// Struct that handle obtaining and refreshing access tokens. @@ -509,21 +502,21 @@ mod test { assert_eq!(get_socket_address("http://127.0.0.1/foo"), None); assert_eq!(get_socket_address("http://127.0.0.1:/foo"), None); assert_eq!(get_socket_address("http://[::1]/foo"), None); - // Not localhost - assert_eq!(get_socket_address("http://56.0.0.1:1234/foo"), None); - assert_eq!( - get_socket_address("http://[3ffe:2a00:100:7031::1]:1234/foo"), - None - ); // Not http assert_eq!(get_socket_address("https://127.0.0.1/foo"), None); } #[test] - fn get_socket_address_localhost() { + fn get_socket_address_some() { let localhost_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1234); let localhost_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8888); + let addr_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 1234); + let addr_v6 = SocketAddr::new( + IpAddr::V6(Ipv6Addr::new(0x2001, 0x4860, 0x4860, 0, 0, 0, 0, 0x8888)), + 8888, + ); + // Loopback addresses assert_eq!( get_socket_address("http://127.0.0.1:1234/foo"), Some(localhost_v4) @@ -536,5 +529,12 @@ mod test { get_socket_address("http://[::1]:8888/foo"), Some(localhost_v6) ); + + // Non-loopback addresses + assert_eq!(get_socket_address("http://8.8.8.8:1234/foo"), Some(addr_v4)); + assert_eq!( + get_socket_address("http://[2001:4860:4860::8888]:8888/foo"), + Some(addr_v6) + ); } }