Implement support for ID tokens

For google stuff these are relevant when trying to invoke e.g. Cloud
Run services. I'm not at all knowledgeable enough with OAuth to be able
to tell if what I'm doing here is correct.

This is a breaking change. `AccessToken` got renamed to just `Token`
(since it now encompasses more than just `access_token` and there are
some changes to the `TokenInfo` type too.

Sponsored by: standard.ai
This commit is contained in:
Simonas Kazlauskas
2021-06-28 15:20:35 +03:00
parent ac0e5f606a
commit 4e54fbaeaf
7 changed files with 88 additions and 72 deletions

View File

@@ -92,7 +92,7 @@ async fn test_device_success() {
.token(&["https://www.googleapis.com/scope/1"])
.await
.expect("token failed");
assert_eq!("accesstoken", token.as_str());
assert_eq!("accesstoken", token.access_token().expect("should have access token"));
}
#[tokio::test]
@@ -252,7 +252,7 @@ async fn test_installed_interactive_success() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!("accesstoken", tok.as_str());
assert_eq!("accesstoken", tok.access_token().expect("should have access token"));
}
#[tokio::test]
@@ -281,7 +281,7 @@ async fn test_installed_redirect_success() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!("accesstoken", tok.as_str());
assert_eq!("accesstoken", tok.access_token().expect("should have access token"));
}
#[tokio::test]
@@ -350,7 +350,7 @@ async fn test_service_account_success() {
.token(&["https://www.googleapis.com/auth/pubsub"])
.await
.expect("token failed");
assert!(tok.as_str().contains("ya29.c.ElouBywiys0Ly"));
assert!(tok.access_token().expect("should have access token").contains("ya29.c.ElouBywiys0Ly"));
assert!(Utc::now() + chrono::Duration::seconds(3600) >= tok.expiration_time().unwrap());
}
@@ -401,7 +401,7 @@ async fn test_refresh() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!("accesstoken", tok.as_str());
assert_eq!("accesstoken", tok.access_token().expect("should have access token"));
server.expect(
Expectation::matching(all_of![
@@ -422,7 +422,7 @@ async fn test_refresh() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!("accesstoken2", tok.as_str());
assert_eq!("accesstoken2", tok.access_token().expect("should have access token"));
server.expect(
Expectation::matching(all_of![
@@ -443,7 +443,7 @@ async fn test_refresh() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!("accesstoken3", tok.as_str());
assert_eq!("accesstoken3", tok.access_token().expect("should have access token"));
server.expect(
Expectation::matching(all_of![
@@ -503,7 +503,7 @@ async fn test_memory_storage() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!(token1.as_str(), "accesstoken");
assert_eq!(token1.access_token().expect("should have access token"), "accesstoken");
assert_eq!(token1, token2);
// Create a new authenticator. This authenticator does not share a cache
@@ -529,7 +529,7 @@ async fn test_memory_storage() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!(token3.as_str(), "accesstoken2");
assert_eq!(token3.access_token().expect("should have access token"), "accesstoken2");
}
#[tokio::test]
@@ -571,7 +571,7 @@ async fn test_disk_storage() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!(token1.as_str(), "accesstoken");
assert_eq!(token1.access_token().expect("should have access token"), "accesstoken");
assert_eq!(token1, token2);
}
@@ -593,6 +593,6 @@ async fn test_disk_storage() {
.token(&["https://googleapis.com/some/scope"])
.await
.expect("failed to get token");
assert_eq!(token1.as_str(), "accesstoken");
assert_eq!(token1.access_token().expect("should have access token"), "accesstoken");
assert_eq!(token1, token2);
}