Struct google_cloud_auth::Config
source · Fields§
§audience: Option<&'a str>§scopes: Option<&'a [&'a str]>Implementations§
source§impl Config<'_>
impl Config<'_>
sourcepub fn scopes_to_string(&self, sep: &str) -> String
pub fn scopes_to_string(&self, sep: &str) -> String
Examples found in repository?
src/lib.rs (line 95)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
pub async fn create_token_source_from_project(
project: &Project,
config: Config<'_>,
) -> Result<Box<dyn TokenSource>, error::Error> {
match project {
Project::FromFile(file) => {
let ts = credentials_from_json_with_params(file, &config)?;
let token = ts.token().await?;
Ok(Box::new(ReuseTokenSource::new(ts, token)))
}
Project::FromMetadataServer(_) => {
let ts = ComputeTokenSource::new(&config.scopes_to_string(","))?;
let token = ts.token().await?;
Ok(Box::new(ReuseTokenSource::new(Box::new(ts), token)))
}
}
}
/// create_token_source creates the token source
pub async fn create_token_source(config: Config<'_>) -> Result<Box<dyn TokenSource>, error::Error> {
let project = project().await?;
create_token_source_from_project(&project, config).await
}
fn credentials_from_json_with_params(
credentials: &CredentialsFile,
config: &Config,
) -> Result<Box<dyn TokenSource>, error::Error> {
match credentials.tp.as_str() {
SERVICE_ACCOUNT_KEY => {
match config.audience {
None => {
if config.scopes.is_none() {
return Err(error::Error::ScopeOrAudienceRequired);
}
// use Standard OAuth 2.0 Flow
let source =
OAuth2ServiceAccountTokenSource::new(credentials, config.scopes_to_string(" ").as_str())?;
Ok(Box::new(source))
}
Some(audience) => {
// use self-signed JWT.
let source = ServiceAccountTokenSource::new(credentials, audience)?;
Ok(Box::new(source))
}
}
}
USER_CREDENTIALS_KEY => Ok(Box::new(UserAccountTokenSource::new(credentials)?)),
//TODO support GDC https://console.developers.google.com,
//TODO support external account
_ => Err(error::Error::UnsupportedAccountType(credentials.tp.to_string())),
}
}