Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify encoded value generation fixing lifetime issue #1000

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions sdk/identity/src/device_code_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ where
tenant_id
);

let mut encoded = form_urlencoded::Serializer::new(String::new());
let encoded = encoded.append_pair("client_id", client_id.as_str());
let encoded = encoded.append_pair("scope", &scopes.join(" "));
let encoded = encoded.finish();
let encoded = form_urlencoded::Serializer::new(String::new())
.append_pair("client_id", client_id.as_str())
.append_pair("scope", &scopes.join(" "))
.finish();

let rsp = post_form(http_client.clone(), url, encoded).await?;
let rsp_status = rsp.status();
Expand Down Expand Up @@ -116,12 +116,11 @@ impl<'a> DeviceCodePhaseOneResponse<'a> {
// last poll and wait only the delta.
new_timer(Duration::from_secs(self.interval)).await;

let mut encoded = form_urlencoded::Serializer::new(String::new());
let encoded = encoded
.append_pair("grant_type", "urn:ietf:params:oauth:grant-type:device_code");
let encoded = encoded.append_pair("client_id", self.client_id.as_str());
let encoded = encoded.append_pair("device_code", &self.device_code);
let encoded = encoded.finish();
let encoded = form_urlencoded::Serializer::new(String::new())
.append_pair("grant_type", "urn:ietf:params:oauth:grant-type:device_code")
.append_pair("client_id", self.client_id.as_str())
.append_pair("device_code", &self.device_code)
.finish();

let http_client = self.http_client.clone().unwrap();

Expand Down Expand Up @@ -184,3 +183,20 @@ async fn post_form(
req.set_body(form_body);
http_client.execute_request(&req).await
}

#[cfg(test)]
mod tests {
use super::*;

fn require_send<T: Send>(_t: T) {}

#[test]
fn ensure_that_start_is_send() {
require_send(start(
azure_core::new_http_client(),
"UNUSED",
&ClientId::new("UNUSED".to_owned()),
&[],
));
}
}