Skip to content

Commit c3d9ee0

Browse files
authored
feat: Add projectId getter to GoogleCredentials (#1813)
* feat: Add projectId getter to GoogleCredentials * chore: Fix lint issues * chore: Add javadoc for public method
1 parent b910dad commit c3d9ee0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ static String getIssuerSubjectValue(String projectId, String serviceIdentityName
276276
return String.format("system:serviceaccount:%s:%s", projectId, serviceIdentityName);
277277
}
278278

279+
/**
280+
* @return the projectId set in the GDCH SA Key file or the user set projectId
281+
*/
282+
@Override
279283
public final String getProjectId() {
280284
return projectId;
281285
}

oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ public String getQuotaProjectId() {
514514
return this.quotaProjectId;
515515
}
516516

517+
/**
518+
* The projectId value for a Credential type. Since not all GoogleCredentials subclass have a
519+
* projectId associated, the projectId may be null. A subset of GoogleCredentials subclasses will
520+
* override to return their projectId.
521+
*
522+
* @return the project id for a Credential type
523+
*/
524+
public String getProjectId() {
525+
return null;
526+
}
527+
517528
/**
518529
* Indicates whether the credentials require scopes to be specified via a call to {@link
519530
* GoogleCredentials#createScoped} before use.

oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ public final String getServiceAccountUser() {
798798
return serviceAccountUser;
799799
}
800800

801+
/**
802+
* @return the projectId set in the SA Key file or the user set projectId
803+
*/
804+
@Override
801805
public final String getProjectId() {
802806
return projectId;
803807
}

0 commit comments

Comments
 (0)