1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! A [`reqwest`] client for [`oauth2`].
//!
//! # Motivation
//!
//! The `reqwest` client [bundled](https://docs.rs/oauth2/latest/oauth2/#http-clients) with `oauth2`
//! supports `reqwest` version 0.12. This separate crate supports `reqwest` version 0.13 and is
//! intended to support future versions of `reqwest` without needing a new SemVer major version
//! number for `oauth2` (which would otherwise be required due to breaking changes to that crate's
//! public API).
//!
//! # Usage
//!
//! To get started, add the following dependencies to your crate's `Cargo.toml`:
//! ```toml
//! # Disables oauth2's default reqwest 0.12 client.
//! oauth2 = { version = "5", default-features = false }
//!
//! # Imports reqwest without any feature flags enabled.
//!
//! # Enables reqwest's default features.
//! reqwest = "0.13"
//! # Alternatively, specify the desired set of features:
//! # reqwest = { version = "0.13", default-features = false, features = ["native-tls"] }
//! ```
//!
//! For flexibility, this crate disables all of `reqwest`'s Cargo feature flags by default. To
//! enable specific `reqwest` features (including its default `rustls` feature), separately import
//! `reqwest` in your crate's `Cargo.toml` and specify the
//! [desired features](https://docs.rs/crate/reqwest/latest/features). This approach leverages Cargo
//! [feature unification](https://doc.rust-lang.org/cargo/reference/features.html#feature-unification).
//! While this approach requires a separate import, it provides maximum flexibility and reduces the
//! need for future breaking changes to this crate.
//!
//! ## Asynchronous Client
//!
//! To use the async `reqwest` client, simply wrap the `reqwest` [`Client`](reqwest::Client) with
//! this crate's [`ReqwestClient`] and pass the `ReqwestClient` to the desired `request_async`
//! method:
//!
//! ```rust,no_run
//! use oauth2_reqwest::ReqwestClient;
//!
//! # async fn err_wrapper() -> Result<(), anyhow::Error> {
//! # let client = oauth2::basic::BasicClient::new(oauth2::ClientId::new("client_id".to_string()))
//! # .set_token_uri(oauth2::TokenUrl::new("http://token".to_string())?);
//! let reqwest_client = reqwest::ClientBuilder::new()
//! // Following redirects opens the client up to SSRF vulnerabilities.
//! .redirect(reqwest::redirect::Policy::none())
//! .build()
//! .expect("Client should build");
//! let http_client = ReqwestClient::from(reqwest_client);
//!
//! # let code = oauth2::AuthorizationCode::new("code".to_string());
//! // This code assumes `client` is a previously constructed `oauth2::Client` and `code` is an
//! // `oauth2::AuthorizationCode`.
//! let token_result = client
//! .exchange_code(code)
//! .request_async(&http_client)
//! .await?;
//!
//! # Ok(())
//! # }
//! ```
//!
//! ## Synchronous Client
//!
//! To use the blocking `reqwest` client, first enable the `blocking` feature in `Cargo.toml`:
//! ```toml
//! ```
//!
//! Then, simply wrap the `reqwest` blocking [`Client`](reqwest::blocking::Client) with
//! this crate's [`ReqwestBlockingClient`] and pass the `ReqwestBlockingClient` to the desired
//! `request` method:
//!
//! ```rust,no_run
//! # #[cfg(feature = "blocking")]
//! use oauth2_reqwest::ReqwestBlockingClient;
//!
//! # #[cfg(feature = "blocking")]
//! # fn err_wrapper() -> Result<(), anyhow::Error> {
//! # let client = oauth2::basic::BasicClient::new(oauth2::ClientId::new("client_id".to_string()))
//! # .set_token_uri(oauth2::TokenUrl::new("http://token".to_string())?);
//! let reqwest_client = reqwest::blocking::ClientBuilder::new()
//! // Following redirects opens the client up to SSRF vulnerabilities.
//! .redirect(reqwest::redirect::Policy::none())
//! .build()
//! .expect("Client should build");
//! let http_client = ReqwestBlockingClient::from(reqwest_client);
//!
//! # let code = oauth2::AuthorizationCode::new("code".to_string());
//! // This code assumes `client` is a previously constructed `oauth2::Client` and `code` is an
//! // `oauth2::AuthorizationCode`.
//! let token_result = client
//! .exchange_code(code)
//! .request(&http_client)?;
//!
//! # Ok(())
//! # }
//! ```
use ;
use Future;
use Pin;
/// Asynchronous `reqwest` [`Client`](reqwest::Client) wrapper.
///
/// See the [crate-level documentation](crate) for usage instructions.
;
pub use ReqwestBlockingClient;