Account for the fact that access tokens are optional now.

This commit is contained in:
Joe Neeman
2022-10-17 16:35:10 -05:00
parent e907226c3c
commit acf898f10c
2 changed files with 12 additions and 2 deletions

View File

@@ -154,6 +154,8 @@ pub enum Error {
UserError(String),
/// A lower level IO error.
LowLevelError(io::Error),
/// We required an access token, but received a response that didn't contain one.
MissingAccessToken,
/// Other errors produced by a storage provider
OtherError(anyhow::Error),
}
@@ -206,6 +208,13 @@ impl fmt::Display for Error {
}
Error::UserError(ref s) => s.fmt(f),
Error::LowLevelError(ref e) => e.fmt(f),
Error::MissingAccessToken => {
write!(
f,
"Expected an access token, but received a response without one"
)?;
Ok(())
}
Error::OtherError(ref e) => e.fmt(f),
}
}

View File

@@ -55,7 +55,7 @@ impl From<TokenResponse> for TokenInfo {
)
.ok();
TokenInfo {
access_token: resp.access_token,
access_token: Some(resp.access_token),
refresh_token: None,
expires_at,
id_token: None,
@@ -99,7 +99,8 @@ impl ServiceAccountImpersonationFlow {
.inner_flow
.token(hyper_client, scopes)
.await?
.access_token;
.access_token
.ok_or(Error::MissingAccessToken)?;
let scopes: Vec<_> = scopes.iter().map(|s| s.as_ref()).collect();
let req_body = Request {