Interface CredentialsHelper
- All Known Implementing Classes:
GoogleCredentialsHelper
public interface CredentialsHelper
该接口提供了一个方法,用于将服务账户的 JSON 字符串转换为 Google Credentials 对象。
此外,该类还包含一些辅助方法,用于帮助将凭据数据传输到 `HttpRequest.Builder` 对象中。
-
方法概述
Modifier and TypeMethodDescriptioncom.google.auth.CredentialsgetGoogleCredentials(@Nullable String serviceAccountJson) 将服务账户的 JSON 字符串转换为 Google Credentials 对象。static HttpRequest.BuilderpopulateHeaders(HttpRequest.Builder builder, com.google.auth.Credentials credentials) 使用凭据中的元数据,填充 `HttpRequest.Builder` 中的头部信息(例如 `Authorization` 或 `x-goog-project`)。
-
方法详细信息(Method Details)
-
getGoogleCredentials
com.google.auth.Credentials getGoogleCredentials(@Nullable String serviceAccountJson) throws IOException 将服务账户的 JSON 字符串转换为 Google Credentials 对象。- Parameters:
serviceAccountJson- The service account JSON string.- Returns:
- A Google Credentials object.
- Throws:
IOException- when an error occurs during the conversion.
-
populateHeaders
static HttpRequest.Builder populateHeaders(HttpRequest.Builder builder, com.google.auth.Credentials credentials) throws IOException 使用凭据中的元数据,填充 `HttpRequest.Builder` 中的头部信息(例如 `Authorization` 或 `x-goog-project`)。- Parameters:
builder- HttpRequest.Builder object to populate the headerscredentials- Credentials object containing the metadata- Returns:
- HttpRequest.Builder object with the headers populated
- Throws:
IOException- if an error occurs when getting the metadata from the credentials
-