pub struct Builder { /* private fields */ }Expand description
A builder for constructing user_account Credentials instance.
§Example
let authorized_user = serde_json::json!({ /* add details here */ });
let credentials = Builder::new(authorized_user).build();
})Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(authorized_user: Value) -> Self
pub fn new(authorized_user: Value) -> Self
Creates a new builder using authorized_user JSON value.
The authorized_user JSON is typically generated when a user
authenticates using the application-default login process.
Sourcepub fn with_token_uri<S: Into<String>>(self, token_uri: S) -> Self
pub fn with_token_uri<S: Into<String>>(self, token_uri: S) -> Self
Sets the URI for the token endpoint used to fetch access tokens.
Any value provided here overrides a token_uri value from the input authorized_user JSON.
Defaults to https://oauth2.googleapis.com/token if not specified here or in the authorized_user JSON.
§Example
let authorized_user = serde_json::json!({ /* add details here */ });
let credentials = Builder::new(authorized_user)
.with_token_uri("https://oauth2-FOOBAR.p.googleapis.com")
.build();Sourcepub fn with_scopes<I, S>(self, scopes: I) -> Self
pub fn with_scopes<I, S>(self, scopes: I) -> Self
Sets the scopes for these credentials.
scopes define the permissions being requested for this specific access token
when interacting with a service. For example, https://www.googleapis.com/auth/devstorage.read_write.
IAM permissions, on the other hand, define the underlying capabilities
the user account possesses within a system. For example, storage.buckets.delete.
When a token generated with specific scopes is used, the request must be permitted
by both the user account’s underlying IAM permissions and the scopes requested
for the token. Therefore, scopes act as an additional restriction on what the token
can be used for.
§Example
let authorized_user = serde_json::json!({ /* add details here */ });
let credentials = Builder::new(authorized_user)
.with_scopes(["https://www.googleapis.com/auth/pubsub"])
.build();Sourcepub fn with_quota_project_id<S: Into<String>>(self, quota_project_id: S) -> Self
pub fn with_quota_project_id<S: Into<String>>(self, quota_project_id: S) -> Self
Sets the quota project for these credentials.
In some services, you can use an account in
one project for authentication and authorization, and charge
the usage to a different project. This requires that the
user has serviceusage.services.use permissions on the quota project.
Any value set here overrides a quota_project_id value from the
input authorized_user JSON.
§Example
let authorized_user = serde_json::json!("{ /* add details here */ }");
let credentials = Builder::new(authorized_user)
.with_quota_project_id("my-project")
.build();Sourcepub fn build(self) -> Result<Credentials, CredentialsError>
pub fn build(self) -> Result<Credentials, CredentialsError>
Returns a Credentials instance with the configured settings.
§Errors
Returns a CredentialsError if the authorized_user
provided to Builder::new cannot be successfully deserialized into the
expected format. This typically happens if the JSON value is malformed or
missing required fields. For more information, on how to generate
authorized_user json, consult the relevant section in the
application-default credentials guide.