Skip to content

Commit fba507b

Browse files
authored
fix(auth): Migrate IAM SignBlob to IAMCredentials SignBlob (#480)
* Migrate IAM SignBlob to IAMCredentials SignBlob Point all SignBlob calls to IAMCredentials * Fix FirebaseToken tests Change proto field to fix the test
1 parent 0b356e1 commit fba507b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/main/java/com/google/firebase/auth/internal/CryptoSigners.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public String getAccount() {
6565

6666
/**
6767
* @ {@link CryptoSigner} implementation that uses the
68-
* <a href="https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob">
69-
* Google IAM service</a> to sign data.
68+
* <a href=https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob">
69+
* Google IAMCredentials service</a> to sign data.
7070
*/
7171
static class IAMCryptoSigner implements CryptoSigner {
7272

7373
private static final String IAM_SIGN_BLOB_URL =
74-
"https://iam.googleapis.com/v1/projects/-/serviceAccounts/%s:signBlob";
74+
"https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/%s:signBlob";
7575

7676
private final String serviceAccount;
7777
private final ErrorHandlingHttpClient<FirebaseAuthException> httpClient;
@@ -95,11 +95,11 @@ void setInterceptor(HttpResponseInterceptor interceptor) {
9595
@Override
9696
public byte[] sign(byte[] payload) throws FirebaseAuthException {
9797
String encodedPayload = BaseEncoding.base64().encode(payload);
98-
Map<String, String> content = ImmutableMap.of("bytesToSign", encodedPayload);
98+
Map<String, String> content = ImmutableMap.of("payload", encodedPayload);
9999
String encodedUrl = String.format(IAM_SIGN_BLOB_URL, serviceAccount);
100100
HttpRequestInfo requestInfo = HttpRequestInfo.buildJsonPostRequest(encodedUrl, content);
101101
GenericJson parsed = httpClient.sendAndParse(requestInfo, GenericJson.class);
102-
return BaseEncoding.base64().decode((String) parsed.get("signature"));
102+
return BaseEncoding.base64().decode((String) parsed.get("signedBlob"));
103103
}
104104

105105
@Override

src/test/java/com/google/firebase/auth/FirebaseCustomTokenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testCreateCustomTokenWithDeveloperClaims() throws Exception {
9292
public void testCreateCustomTokenWithoutServiceAccountCredentials() throws Exception {
9393
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
9494
String content = Utils.getDefaultJsonFactory().toString(
95-
ImmutableMap.of("signature", BaseEncoding.base64().encode("test-signature".getBytes())));
95+
ImmutableMap.of("signedBlob", BaseEncoding.base64().encode("test-signature".getBytes())));
9696
response.setContent(content);
9797
MockHttpTransport transport = new MultiRequestMockHttpTransport(ImmutableList.of(response));
9898

@@ -117,7 +117,7 @@ public void testCreateCustomTokenWithoutServiceAccountCredentials() throws Excep
117117
@Test
118118
public void testCreateCustomTokenWithDiscoveredServiceAccount() throws Exception {
119119
String content = Utils.getDefaultJsonFactory().toString(
120-
ImmutableMap.of("signature", BaseEncoding.base64().encode("test-signature".getBytes())));
120+
ImmutableMap.of("signedBlob", BaseEncoding.base64().encode("test-signature".getBytes())));
121121
List<MockLowLevelHttpResponse> responses = ImmutableList.of(
122122
// Service account discovery response
123123
new MockLowLevelHttpResponse().setContent("[email protected]"),

src/test/java/com/google/firebase/auth/internal/CryptoSignersTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testInvalidServiceAccountCryptoSigner() {
7171
public void testIAMCryptoSigner() throws Exception {
7272
String signature = BaseEncoding.base64().encode("signed-bytes".getBytes());
7373
String response = Utils.getDefaultJsonFactory().toString(
74-
ImmutableMap.of("signature", signature));
74+
ImmutableMap.of("signedBlob", signature));
7575
MockHttpTransport transport = new MockHttpTransport.Builder()
7676
.setLowLevelHttpResponse(new MockLowLevelHttpResponse().setContent(response))
7777
.build();
@@ -84,7 +84,7 @@ public void testIAMCryptoSigner() throws Exception {
8484

8585
byte[] data = signer.sign("foo".getBytes());
8686
assertArrayEquals("signed-bytes".getBytes(), data);
87-
final String url = "https://iam.googleapis.com/v1/projects/-/serviceAccounts/"
87+
final String url = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/"
8888
+ "[email protected]:signBlob";
8989
assertEquals(url, interceptor.getResponse().getRequest().getUrl().toString());
9090
}
@@ -150,7 +150,7 @@ public void testInvalidIAMCryptoSigner() {
150150
public void testMetadataService() throws Exception {
151151
String signature = BaseEncoding.base64().encode("signed-bytes".getBytes());
152152
String response = Utils.getDefaultJsonFactory().toString(
153-
ImmutableMap.of("signature", signature));
153+
ImmutableMap.of("signedBlob", signature));
154154
MockHttpTransport transport = new MultiRequestMockHttpTransport(
155155
ImmutableList.of(
156156
new MockLowLevelHttpResponse().setContent("[email protected]"),
@@ -168,7 +168,7 @@ public void testMetadataService() throws Exception {
168168

169169
byte[] data = signer.sign("foo".getBytes());
170170
assertArrayEquals("signed-bytes".getBytes(), data);
171-
final String url = "https://iam.googleapis.com/v1/projects/-/serviceAccounts/"
171+
final String url = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/"
172172
+ "[email protected]:signBlob";
173173
HttpRequest request = interceptor.getResponse().getRequest();
174174
assertEquals(url, request.getUrl().toString());
@@ -179,7 +179,7 @@ public void testMetadataService() throws Exception {
179179
public void testExplicitServiceAccountEmail() throws Exception {
180180
String signature = BaseEncoding.base64().encode("signed-bytes".getBytes());
181181
String response = Utils.getDefaultJsonFactory().toString(
182-
ImmutableMap.of("signature", signature));
182+
ImmutableMap.of("signedBlob", signature));
183183

184184
// Explicit service account should get precedence
185185
MockHttpTransport transport = new MultiRequestMockHttpTransport(
@@ -198,7 +198,7 @@ public void testExplicitServiceAccountEmail() throws Exception {
198198

199199
byte[] data = signer.sign("foo".getBytes());
200200
assertArrayEquals("signed-bytes".getBytes(), data);
201-
final String url = "https://iam.googleapis.com/v1/projects/-/serviceAccounts/"
201+
final String url = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/"
202202
+ "[email protected]:signBlob";
203203
HttpRequest request = interceptor.getResponse().getRequest();
204204
assertEquals(url, request.getUrl().toString());

0 commit comments

Comments
 (0)