Skip to content

Commit 6ecc9c8

Browse files
committed
docs(auth): check blank universeDomain in create and clarify Javadocs
1 parent 6052214 commit 6ecc9c8

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ String getCredentialName() {
116116
* Returns the credentials instance from the given access token.
117117
*
118118
* <p>The returned credentials default to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code
119-
* googleapis.com}). To avoid sending a non-default universe access token to {@code
120-
* googleapis.com}, callers using a custom universe domain should use {@link #create(String,
121-
* AccessToken)} instead.
119+
* googleapis.com}). Callers with an access token for a non-default universe domain should use
120+
* {@link #create(String, AccessToken)} to specify the universe domain explicitly.
122121
*
123122
* @param accessToken the access token
124123
* @return the credentials instance
@@ -133,14 +132,14 @@ public static GoogleCredentials create(AccessToken accessToken) {
133132
* <p>If {@code universeDomain} is {@code null} or blank, the returned credentials default to
134133
* {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}).
135134
*
136-
* @param universeDomain the universe domain, or {@code null} to default to {@link
135+
* @param universeDomain the universe domain, or {@code null} or blank to default to {@link
137136
* Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com})
138137
* @param accessToken the access token
139138
* @return the credentials instance
140139
*/
141140
public static GoogleCredentials create(@Nullable String universeDomain, AccessToken accessToken) {
142141
Builder builder = GoogleCredentials.newBuilder().setAccessToken(accessToken);
143-
if (universeDomain != null) {
142+
if (universeDomain != null && !universeDomain.trim().isEmpty()) {
144143
builder.setUniverseDomain(universeDomain);
145144
}
146145
return builder.build();
@@ -431,8 +430,9 @@ protected GoogleCredentials() {
431430
*
432431
* <p>Deprecated, please use the {@link GoogleCredentials#GoogleCredentials(Builder)} constructor
433432
* whenever possible. Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code
434-
* googleapis.com}). Callers using a custom universe domain should use {@link #newBuilder()} with
435-
* {@link Builder#setUniverseDomain(String)} or {@link #create(String, AccessToken)}.
433+
* googleapis.com}). Callers with an access token for a non-default universe domain should use
434+
* {@link #create(String, AccessToken)} (or {@link #newBuilder()} with {@link
435+
* Builder#setUniverseDomain(String)}) to specify the universe domain explicitly.
436436
*
437437
* @param accessToken initial or temporary access token
438438
* @param quotaProjectId a quotaProjectId, a project id to be used for billing purposes
@@ -449,7 +449,8 @@ protected GoogleCredentials(@Nullable AccessToken accessToken, @Nullable String
449449
* Constructor with explicit access token.
450450
*
451451
* <p>Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code googleapis.com}). Callers
452-
* using a custom universe domain should use {@link #create(String, AccessToken)} instead.
452+
* with an access token for a non-default universe domain should use {@link #create(String,
453+
* AccessToken)} to specify the universe domain explicitly.
453454
*
454455
* @param accessToken initial or temporary access token
455456
*/
@@ -484,8 +485,9 @@ protected GoogleCredentials(Builder builder) {
484485
*
485486
* <p>Deprecated, please use the {@link GoogleCredentials#GoogleCredentials(Builder)} constructor
486487
* whenever possible. Defaults to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE} ({@code
487-
* googleapis.com}). Callers using a custom universe domain should use {@link #newBuilder()} with
488-
* {@link Builder#setUniverseDomain(String)}.
488+
* googleapis.com}). Callers with an access token for a non-default universe domain should use
489+
* {@link #create(String, AccessToken)} (or {@link #newBuilder()} with {@link
490+
* Builder#setUniverseDomain(String)}) to specify the universe domain explicitly.
489491
*
490492
* @param accessToken initial or temporary access token
491493
*/

0 commit comments

Comments
 (0)