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

chore: Remove reference to reqwest::blocking #60

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
sha2 = "0.10"
time = { version = "0.3.9", features = ["macros", "formatting", "parsing"] }
tokio = { version = "1.17", features = ["full"] }

[dev-dependencies]
aws-sigv4 = "0.12"
Expand All @@ -43,3 +42,4 @@ dotenv = "0.15"
env_logger = "0.9"
isahc = { version = "1.7.2", features = ["json"] }
temp-env = "0.2"
tokio = { version = "1.17", features = ["full"] }
22 changes: 10 additions & 12 deletions src/services/google/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::sync::RwLock;

use anyhow::{anyhow, Result};
use http::{header, StatusCode};
use isahc::{ReadResponseExt, Request};
use jsonwebtoken::{Algorithm, EncodingKey, Header};
use log::error;
use reqwest::blocking::{Body, Request};

use super::constants::GOOGLE_APPLICATION_CREDENTIALS;
use super::credential::{Claims, Credential, CredentialLoader, Token};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Builder {
scope,
credential,
token: Arc::new(RwLock::new((Token::default(), DateTime::now_utc()))),
client: reqwest::blocking::Client::new(),
client: isahc::HttpClient::new()?,
})
}
}
Expand All @@ -102,7 +102,7 @@ pub struct Signer {
credential: Credential,
token: Arc<RwLock<(Token, DateTime)>>,

client: reqwest::blocking::Client,
client: isahc::HttpClient,
}

impl Signer {
Expand All @@ -121,22 +121,20 @@ impl Signer {
)?;

let mut req = Request::new(
http::Method::POST,
"https://oauth2.googleapis.com/token".parse()?,
form_urlencoded::Serializer::new(String::new())
.append_pair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.append_pair("assertion", &jwt)
.finish(),
);
*req.method_mut() = http::Method::POST;
*req.uri_mut() = "https://oauth2.googleapis.com/token".parse()?;
// Insert content_type in header
req.headers_mut().insert(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded".parse()?,
);
*req.body_mut() = Some(Body::from(
form_urlencoded::Serializer::new(String::new())
.append_pair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.append_pair("assertion", &jwt)
.finish(),
));

let resp = self.client.execute(req)?;
let mut resp = self.client.send(req)?;
if resp.status() != StatusCode::OK {
error!("exchange token got unexpected response: {:?}", resp);
return Err(anyhow!("exchange token failed: {:?}", resp));
Expand Down