Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,34 @@
/**
* Returns the credentials instance from the given access token.
*
* <p>The returned credentials default to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code
* googleapis.com}). Callers with an access token for a non-default universe domain should use
* {@link #create(String, AccessToken)} to specify the universe domain explicitly.
*
* @param accessToken the access token
* @return the credentials instance
*/
public static GoogleCredentials create(AccessToken accessToken) {
return GoogleCredentials.newBuilder().setAccessToken(accessToken).build();
return create(null, accessToken);
}

/**
* Returns the credentials instance from the given access token and universe domain.
*
* @param universeDomain the universe domain
* <p>If {@code universeDomain} is {@code null} or blank, the returned credentials default to
* {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}).
*
* @param universeDomain the universe domain, or {@code null} or blank to default to {@link
* Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com})
* @param accessToken the access token
* @return the credentials instance
*/
public static GoogleCredentials create(String universeDomain, AccessToken accessToken) {
return GoogleCredentials.newBuilder()
.setAccessToken(accessToken)
.setUniverseDomain(universeDomain)
.build();
public static GoogleCredentials create(@Nullable String universeDomain, AccessToken accessToken) {
Builder builder = GoogleCredentials.newBuilder().setAccessToken(accessToken);
if (universeDomain != null && !universeDomain.trim().isEmpty()) {
builder.setUniverseDomain(universeDomain);
}
return builder.build();
}

/**
Expand Down Expand Up @@ -216,7 +225,7 @@
* <p>Regardless of the method used, it is always your responsibility to validate configurations
* received from external sources.
*
* <p>See the {@see <a

Check failure on line 228 in google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

View workflow job for this annotation

GitHub Actions / bom-content-test

no tag name after @

Check failure on line 228 in google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

View workflow job for this annotation

GitHub Actions / BomContentAssertionsTest (Test for assertion logic in BomContentTest)

no tag name after @
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}
* for more details.
*
Expand Down Expand Up @@ -283,7 +292,7 @@
* <p>Regardless of the method used, it is always your responsibility to validate configurations
* received from external sources.
*
* <p>See the {@see <a

Check failure on line 295 in google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

View workflow job for this annotation

GitHub Actions / bom-content-test

no tag name after @

Check failure on line 295 in google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

View workflow job for this annotation

GitHub Actions / BomContentAssertionsTest (Test for assertion logic in BomContentTest)

no tag name after @
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}
* for more details.
*
Expand Down Expand Up @@ -419,11 +428,17 @@
/**
* Constructor with an explicit access token and quotaProjectId.
*
* <p>Deprecated, please use the {@link GoogleCredentials#GoogleCredentials(Builder)} constructor
* whenever possible.
* <p>Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}). Callers
* with an access token for a non-default universe domain should use {@link #create(String,
* AccessToken)} (or {@link #newBuilder()} with {@link Builder#setAccessToken(AccessToken)} and
* {@link Builder#setUniverseDomain(String)}) to specify the universe domain explicitly.
*
* @param accessToken initial or temporary access token
* @param quotaProjectId a quotaProjectId, a project id to be used for billing purposes
* @deprecated Use {@link #GoogleCredentials(Builder)} for subclasses, or {@link #newBuilder()}
* with {@link Builder#setAccessToken(AccessToken)} and {@link
* Builder#setQuotaProjectId(String)} (and {@link Builder#setUniverseDomain(String)} for a
* non-default universe domain).
*/
@Deprecated
protected GoogleCredentials(@Nullable AccessToken accessToken, @Nullable String quotaProjectId) {
Expand All @@ -436,7 +451,13 @@
/**
* Constructor with explicit access token.
*
* <p>Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}). Callers
* with an access token for a non-default universe domain should use {@link #create(String,
* AccessToken)} to specify the universe domain explicitly.
*
* @param accessToken initial or temporary access token
* @deprecated Use {@link #create(AccessToken)} for {@code googleapis.com}, or {@link
* #create(String, AccessToken)} to specify a universe domain explicitly.
*/
@Deprecated
public GoogleCredentials(AccessToken accessToken) {
Expand Down Expand Up @@ -467,10 +488,15 @@
/**
* Constructor with explicit access token and refresh margins.
*
* <p>Deprecated, please use the {@link GoogleCredentials#GoogleCredentials(Builder)} constructor
* whenever possible.
* <p>Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}). Callers
* with an access token for a non-default universe domain should use {@link #create(String,
* AccessToken)} (or {@link #newBuilder()} with {@link Builder#setAccessToken(AccessToken)} and
* {@link Builder#setUniverseDomain(String)}) to specify the universe domain explicitly.
*
* @param accessToken initial or temporary access token
* @deprecated Use {@link #GoogleCredentials(Builder)} for subclasses, or {@link #newBuilder()}
* with {@link Builder#setAccessToken(AccessToken)} and {@link
* Builder#setUniverseDomain(String)} for a non-default universe domain.
*/
@Deprecated
protected GoogleCredentials(
Expand Down Expand Up @@ -686,6 +712,15 @@
return this;
}

/**
* Sets the universe domain for the credential.
*
* <p>If unset, {@code null}, or blank, defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE}
* ({@code googleapis.com}).
*
* @param universeDomain the universe domain (for example, {@code googleapis.com})
* @return this builder
*/
public Builder setUniverseDomain(String universeDomain) {
this.universeDomain = universeDomain;
return this;
Expand Down
Loading