Skip to content

Commit 3822e14

Browse files
authored
use oauth2-reqwest crate (#1391)
1 parent 2b4f30e commit 3822e14

File tree

4 files changed

+15
-41
lines changed

4 files changed

+15
-41
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ log = "0.4.29"
3939
md5 = "0.8.0"
4040
newline-converter = "0.3.0"
4141
oauth2 = { version = "5.0.0", default-features = false }
42+
oauth2-reqwest = "0.1.0-alpha.3"
4243
open = "5.3.3"
4344
oxide = { path = "sdk", version = "0.15.0" }
4445
oxide-httpmock = { path = "sdk-httpmock", version = "0.15.0" }

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ indicatif = { workspace = true }
3838
log = { workspace = true }
3939
md5 = { workspace = true }
4040
oauth2 = { workspace = true }
41+
oauth2-reqwest = { workspace = true }
4142
open = { workspace = true }
4243
oxide = { workspace = true, features = ["clap", "extras"] }
4344
oxnet = { workspace = true }

cli/src/cmd_auth.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,45 +56,6 @@ impl RunnableCmd for CmdAuth {
5656
}
5757
}
5858

59-
// Integrate reqwest with oauth2 until oauth2 is updated to support reqwest
60-
// 0.13.
61-
struct ReqwestClient<'a>(&'a reqwest::Client);
62-
63-
impl<'a, 'c> oauth2::AsyncHttpClient<'c> for ReqwestClient<'a> {
64-
type Error = oauth2::HttpClientError<reqwest::Error>;
65-
66-
type Future = std::pin::Pin<
67-
Box<
68-
dyn std::future::Future<Output = Result<oauth2::HttpResponse, Self::Error>>
69-
+ Send
70-
+ Sync
71-
+ 'c,
72-
>,
73-
>;
74-
75-
fn call(&'c self, request: oauth2::HttpRequest) -> Self::Future {
76-
Box::pin(async move {
77-
let response = self
78-
.0
79-
.execute(request.try_into().map_err(Box::new)?)
80-
.await
81-
.map_err(Box::new)?;
82-
83-
let mut builder = http::Response::builder()
84-
.status(response.status())
85-
.version(response.version());
86-
87-
for (name, value) in response.headers().iter() {
88-
builder = builder.header(name, value);
89-
}
90-
91-
builder
92-
.body(response.bytes().await.map_err(Box::new)?.to_vec())
93-
.map_err(oauth2::HttpClientError::Http)
94-
})
95-
}
96-
}
97-
9859
/// Parse and normalize a given host string as a valid URL.
9960
///
10061
/// http(s) are the only supported schemas. If no schema is specified then
@@ -240,7 +201,7 @@ impl CmdAuthLogin {
240201
}
241202

242203
// Make the client for use by oauth2
243-
let client = &ctx
204+
let client = ctx
244205
.client_config()
245206
.make_unauthenticated_client_builder()
246207
.redirect(reqwest::redirect::Policy::none())
@@ -272,7 +233,7 @@ impl CmdAuthLogin {
272233
request = request.add_extra_param("ttl_seconds", ttl.as_secs().to_string());
273234
}
274235

275-
let reqwest_client = ReqwestClient(client);
236+
let reqwest_client = oauth2_reqwest::ReqwestClient::from(client);
276237

277238
let details: StandardDeviceAuthorizationResponse =
278239
request.request_async(&reqwest_client).await?;

0 commit comments

Comments
 (0)