Skip to content

Commit d81aafe

Browse files
committed
move iam endpoint format strings from OAuth2Utils to IamUtils.
1 parent b6e6d1a commit d81aafe

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
* features like signing.
6363
*/
6464
class IamUtils {
65+
66+
// iam credentials endpoints are to be formatted with universe domain and client email
67+
static final String IAM_ID_TOKEN_ENDPOINT_FORMAT =
68+
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:generateIdToken";
69+
static final String IAM_ACCESS_TOKEN_ENDPOINT_FORMAT =
70+
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:generateAccessToken";
71+
static final String IAM_SIGN_BLOB_ENDPOINT_FORMAT =
72+
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:signBlob";
6573
private static final String PARSE_ERROR_MESSAGE = "Error parsing error message response. ";
6674
private static final String PARSE_ERROR_SIGNATURE = "Error parsing signature response. ";
6775

@@ -114,8 +122,7 @@ private static String getSignature(
114122
HttpRequestFactory factory)
115123
throws IOException {
116124
String signBlobUrl =
117-
String.format(
118-
OAuth2Utils.IAM_SIGN_BLOB_ENDPOINT_FORMAT, universeDomain, serviceAccountEmail);
125+
String.format(IAM_SIGN_BLOB_ENDPOINT_FORMAT, universeDomain, serviceAccountEmail);
119126
GenericUrl genericUrl = new GenericUrl(signBlobUrl);
120127

121128
GenericData signRequest = new GenericData();
@@ -203,8 +210,7 @@ static IdToken getIdToken(
203210
throws IOException {
204211

205212
String idTokenUrl =
206-
String.format(
207-
OAuth2Utils.IAM_ID_TOKEN_ENDPOINT_FORMAT, universeDomain, serviceAccountEmail);
213+
String.format(IAM_ID_TOKEN_ENDPOINT_FORMAT, universeDomain, serviceAccountEmail);
208214
GenericUrl genericUrl = new GenericUrl(idTokenUrl);
209215

210216
GenericData idTokenRequest = new GenericData();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public AccessToken refreshAccessToken() throws IOException {
532532
this.iamEndpointOverride != null
533533
? this.iamEndpointOverride
534534
: String.format(
535-
OAuth2Utils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
535+
IamUtils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
536536
getUniverseDomain(),
537537
this.targetPrincipal);
538538

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

-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ class OAuth2Utils {
7777
static final String TOKEN_TYPE_TOKEN_EXCHANGE = "urn:ietf:params:oauth:token-type:token-exchange";
7878
static final String GRANT_TYPE_JWT_BEARER = "urn:ietf:params:oauth:grant-type:jwt-bearer";
7979

80-
// iam credentials endpoints are to be formatted with universe domain and client email
81-
static final String IAM_ID_TOKEN_ENDPOINT_FORMAT =
82-
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:generateIdToken";
83-
84-
static final String IAM_ACCESS_TOKEN_ENDPOINT_FORMAT =
85-
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:generateAccessToken";
86-
static final String IAM_SIGN_BLOB_ENDPOINT_FORMAT =
87-
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s:signBlob";
88-
8980
static final URI TOKEN_SERVER_URI = URI.create("https://oauth2.googleapis.com/token");
9081

9182
static final URI TOKEN_REVOKE_URI = URI.create("https://oauth2.googleapis.com/revoke");

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,7 @@ private IdToken getIdTokenIamEndpoint(String targetAudience) throws IOException
636636
// `getUniverseDomain()` throws an IOException that would need to be caught
637637
URI iamIdTokenUri =
638638
URI.create(
639-
String.format(
640-
OAuth2Utils.IAM_ID_TOKEN_ENDPOINT_FORMAT, getUniverseDomain(), clientEmail));
639+
String.format(IamUtils.IAM_ID_TOKEN_ENDPOINT_FORMAT, getUniverseDomain(), clientEmail));
641640
HttpRequest request = buildIdTokenRequest(iamIdTokenUri, transportFactory, content);
642641
// Use the Access Token from the SSJWT to request the ID Token from IAM Endpoint
643642
request.setHeaders(new HttpHeaders().set(AuthHttpConstants.AUTHORIZATION, accessToken));

oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public class ImpersonatedCredentialsTest extends BaseSerializationTest {
133133
+ ":generateAccessToken";
134134
public static final String DEFAULT_IMPERSONATION_URL =
135135
String.format(
136-
OAuth2Utils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
136+
IamUtils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
137137
DEFAULT_UNIVERSE_DOMAIN,
138138
IMPERSONATED_CLIENT_EMAIL);
139139
private static final String NONGDU_IMPERSONATION_URL =
140140
String.format(
141-
OAuth2Utils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
141+
IamUtils.IAM_ACCESS_TOKEN_ENDPOINT_FORMAT,
142142
TEST_UNIVERSE_DOMAIN,
143143
IMPERSONATED_CLIENT_EMAIL);
144144
public static final String IMPERSONATION_OVERRIDE_URL =

oauth2_http/javatests/com/google/auth/oauth2/MockIAMCredentialsServiceTransport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import static com.google.auth.oauth2.OAuth2Utils.IAM_ID_TOKEN_ENDPOINT_FORMAT;
34+
import static com.google.auth.oauth2.IamUtils.IAM_ID_TOKEN_ENDPOINT_FORMAT;
3535

3636
import com.google.api.client.http.HttpStatusCodes;
3737
import com.google.api.client.http.LowLevelHttpRequest;

0 commit comments

Comments
 (0)