Expand description
§Motivation
The reqwest client bundled 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:
# Disables oauth2's default reqwest 0.12 client.
oauth2 = { version = "5", default-features = false }
# Imports reqwest without any feature flags enabled.
oauth2-reqwest = "0.1.0-alpha.3"
# 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. This approach leverages Cargo
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 with
this crate’s ReqwestClient and pass the ReqwestClient to the desired request_async
method:
use oauth2_reqwest::ReqwestClient;
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);
// 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?;
§Synchronous Client
To use the blocking reqwest client, first enable the blocking feature in Cargo.toml:
oauth2-reqwest = { version = "0.1.0-alpha.3", features = ["blocking"] }Then, simply wrap the reqwest blocking Client with
this crate’s ReqwestBlockingClient and pass the ReqwestBlockingClient to the desired
request method:
use oauth2_reqwest::ReqwestBlockingClient;
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);
// 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)?;
Structs§
- Reqwest
Blocking Client - Synchronous
reqwestblockingClientwrapper. - Reqwest
Client - Asynchronous
reqwestClientwrapper.