diff --git a/Cargo.toml b/Cargo.toml index 80ee7d5..4c74c3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "5.0.1" +version = "5.0.2" authors = ["Sebastian Thiel ", "Lewin Bormann "] repository = "https://github.com/dermesser/yup-oauth2" description = "An oauth2 implementation, providing the 'device', 'service account' and 'installed' authorization flows" diff --git a/src/installed.rs b/src/installed.rs index 41507bb..402ff61 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -36,8 +36,18 @@ where let scopes_string = crate::helper::join(scopes, " "); url.push_str(auth_uri); + + if !url.contains('?') { + url.push('?'); + } else { + match url.chars().last() { + Some('?') | None => {} + Some(_) => url.push('&'), + } + } + vec![ - format!("?scope={}", scopes_string), + format!("scope={}", scopes_string), "&access_type=offline".to_string(), format!("&redirect_uri={}", redirect_uri.unwrap_or(OOB_REDIRECT_URI)), "&response_type=code".to_string(), @@ -371,6 +381,23 @@ mod tests { ); } + #[test] + fn test_request_url_builder_appends_queries() { + assert_eq!( + "https://accounts.google.\ + com/o/oauth2/auth?unknown=testing&scope=email%20profile&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:\ + oob&response_type=code&client_id=812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amr\ + f.apps.googleusercontent.com", + build_authentication_request_url( + "https://accounts.google.com/o/oauth2/auth?unknown=testing", + "812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5am\ + rf.apps.googleusercontent.com", + &["email", "profile"], + None + ) + ); + } + #[tokio::test] async fn test_server_random_local_port() { let addr1 = InstalledFlowServer::run().unwrap().local_addr();