-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--all-features and --no-default-features
This adjusts the code and documentation for `--all-features` and `--no-default-features` to work correctly. With `--no-default-features` no `DefaultAuthenticator` is made available. Users are in control of picking the `Connector` they want to use, and are not forced to stomach a dependency on `rustls` or `hyper-tls` if their TLS implementation of choice doesn't happen to match one of the two. To indicate this, the unstable `doc_cfg` feature is used to build documentation on docs.rs. That way the generated documentation has notices on these types that look as such: > This is supported on crate features hyper-rustls or hyper-tls only. Additionally this functionality is tested via additional coverage in the Actions' CI.
- Loading branch information
Showing
8 changed files
with
107 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
//! This module provides a token source (`GetToken`) that obtains tokens for service accounts. | ||
//! This module provides a flow that obtains tokens for service accounts. | ||
//! | ||
//! Service accounts are usually used by software (i.e., non-human actors) to get access to | ||
//! resources. Currently, this module only works with RS256 JWTs, which makes it at least suitable for | ||
//! authentication with Google services. | ||
//! resources. Currently, this module only works with RS256 JWTs, which makes it at least suitable | ||
//! for authentication with Google services. | ||
//! | ||
//! Resources: | ||
//! - [Using OAuth 2.0 for Server to Server | ||
//! Applications](https://developers.google.com/identity/protocols/OAuth2ServiceAccount) | ||
//! - [JSON Web Tokens](https://jwt.io/) | ||
//! | ||
//! Copyright (c) 2016 Google Inc ([email protected]). | ||
//! | ||
use crate::error::Error; | ||
use crate::types::TokenInfo; | ||
|
@@ -54,8 +54,9 @@ fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, io::Error> { | |
} | ||
} | ||
|
||
/// JSON schema of secret service account key. You can obtain the key from | ||
/// the Cloud Console at https://console.cloud.google.com/. | ||
/// JSON schema of secret service account key. | ||
/// | ||
/// You can obtain the key from the [Cloud Console](https://console.cloud.google.com/). | ||
/// | ||
/// You can use `helpers::read_service_account_key()` as a quick way to read a JSON client | ||
/// secret into a ServiceAccountKey. | ||
|
@@ -210,31 +211,24 @@ impl ServiceAccountFlow { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
use crate::helper::read_service_account_key; | ||
#[cfg(not(feature = "hyper-tls"))] | ||
use hyper_rustls::HttpsConnector; | ||
#[cfg(feature = "hyper-tls")] | ||
use hyper_tls::HttpsConnector; | ||
use crate::authenticator::HyperClientBuilder; | ||
|
||
// Valid but deactivated key. | ||
const TEST_PRIVATE_KEY_PATH: &'static str = "examples/Sanguine-69411a0c0eea.json"; | ||
|
||
// Uncomment this test to verify that we can successfully obtain tokens. | ||
//#[tokio::test] | ||
#[allow(dead_code)] | ||
#[cfg(any(feature = "hyper-rustls", feature = "hyper-tls"))] | ||
async fn test_service_account_e2e() { | ||
let key = read_service_account_key(TEST_PRIVATE_KEY_PATH) | ||
.await | ||
.unwrap(); | ||
let acc = ServiceAccountFlow::new(ServiceAccountFlowOpts { key, subject: None }).unwrap(); | ||
#[cfg(not(feature = "hyper-tls"))] | ||
let https = HttpsConnector::with_native_roots(); | ||
#[cfg(feature = "hyper-tls")] | ||
let https = HttpsConnector::new(); | ||
let client = hyper::Client::builder() | ||
.pool_max_idle_per_host(0) | ||
.build::<_, hyper::Body>(https); | ||
let client = crate::authenticator::DefaultHyperClient.build_hyper_client(); | ||
println!( | ||
"{:?}", | ||
acc.token(&client, &["https://www.googleapis.com/auth/pubsub"]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters