added access token authenticator

This commit is contained in:
chritoep
2022-08-26 08:50:28 +02:00
parent dcc35ac2e0
commit 110c65ab07
3 changed files with 72 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ use yup_oauth2::{
ApplicationDefaultCredentialsAuthenticator, ApplicationDefaultCredentialsFlowOpts,
ApplicationSecret, DeviceFlowAuthenticator, Error, InstalledFlowAuthenticator,
InstalledFlowReturnMethod, ServiceAccountAuthenticator, ServiceAccountKey,
AccessTokenAuthenticator,
};
use std::future::Future;
@@ -643,3 +644,16 @@ async fn test_default_application_credentials_from_metadata_server() {
.unwrap();
assert_eq!(token.as_str(), "accesstoken");
}
#[tokio::test]
async fn test_access_token() {
let authenticator = AccessTokenAuthenticator::with_client("0815".to_string(), DefaultHyperClient)
.build()
.await
.unwrap();
let token = authenticator
.token(&["https://googleapis.com/some/scope"])
.await
.unwrap();
assert_eq!(token.as_str(), "0815".to_string());
}