-
-
Couldn't load subscription status.
- Fork 183
Open
Description
I'm using the first example from the docs, but it doesn't build:
use oauth2::basic::BasicClient;
use oauth2::reqwest;
use oauth2::{
AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, PkceCodeChallenge, RedirectUrl,
Scope, TokenResponse, TokenUrl,
};
use url::Url;
fn main() {
// Create an OAuth2 client by specifying the client ID, client secret, authorization URL and
// token URL.
let client = BasicClient::new(ClientId::new("client_id".to_string()))
.set_client_secret(ClientSecret::new("client_secret".to_string()))
.set_auth_uri(AuthUrl::new("http://authorize".to_string()).unwrap())
.set_token_uri(TokenUrl::new("http://token".to_string()).unwrap())
// Set the URL the user will be redirected to after the authorization process.
.set_redirect_uri(RedirectUrl::new("http://redirect".to_string()).unwrap());
// Generate a PKCE challenge.
let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256();
// Generate the full authorization URL.
let (auth_url, csrf_token) = client
.authorize_url(CsrfToken::new_random)
// Set the desired scopes.
.add_scope(Scope::new("read".to_string()))
.add_scope(Scope::new("write".to_string()))
// Set the PKCE code challenge.
.set_pkce_challenge(pkce_challenge)
.url();
// This is the URL you should redirect the user to, in order to trigger the authorization
// process.
println!("Browse to: {}", auth_url);
// Once the user has been redirected to the redirect URL, you'll have access to the
// authorization code. For security reasons, your code should verify that the `state`
// parameter returned by the server matches `csrf_token`.
let http_client = reqwest::blocking::ClientBuilder::new()
// Following redirects opens the client up to SSRF vulnerabilities.
.redirect(reqwest::redirect::Policy::none())
.build()
.expect("Client should build");
// Now you can trade it for an access token.
let token_result = client
.exchange_code(AuthorizationCode::new(
"some authorization code".to_string(),
))
// Set the PKCE code verifier.
.set_pkce_verifier(pkce_verifier)
.request(&http_client)?;
}Here is the error:
error[E0277]: expected a `Fn(oauth2::http::Request<Vec<u8>>)` closure, found `oauth2::reqwest::blocking::Client`
--> src/main.rs:53:10
|
53 | .request(&http_client)
| ^^^^^^^ expected an `Fn(oauth2::http::Request<Vec<u8>>)` closure, found `oauth2::reqwest::blocking::Client`
|
= help: the trait `Fn(oauth2::http::Request<Vec<u8>>)` is not implemented for `oauth2::reqwest::blocking::Client`
= note: required for `oauth2::reqwest::blocking::Client` to implement `SyncHttpClient`
For more information about this error, try `rustc --explain E0277`.
Metadata
Metadata
Assignees
Labels
No labels