Skip to content

Commit dfd0d7c

Browse files
rlazodaymxn
andauthored
[Functions] Send the placeholder appcheck token in case of error (#6750)
tracking b/399116207 --------- Co-authored-by: Daymon <17409137+daymxn@users.noreply.github.com>
1 parent 7c03f49 commit dfd0d7c

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

firebase-functions/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [fixed] Fixed an issue that prevented the App Check token from being handled correctly in case of error.
23

34
# 21.1.1
45
* [fixed] Resolve Kotlin migration visibility issues

firebase-functions/src/androidTest/java/com/google/firebase/functions/FirebaseContextProviderTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void getContext_whenOnlyAuthIsAvailableAndNotSignedIn_shouldContainOnlyIi
117117
}
118118

119119
@Test
120-
public void getContext_whenOnlyAppCheckIsAvailableAndHasError_shouldContainOnlyIid()
120+
public void getContext_whenOnlyAppCheckIsAvailableAndHasError()
121121
throws ExecutionException, InterruptedException {
122122
FirebaseContextProvider contextProvider =
123123
new FirebaseContextProvider(
@@ -129,11 +129,12 @@ public void getContext_whenOnlyAppCheckIsAvailableAndHasError_shouldContainOnlyI
129129
HttpsCallableContext context = Tasks.await(contextProvider.getContext(false));
130130
assertThat(context.getAuthToken()).isNull();
131131
assertThat(context.getInstanceIdToken()).isEqualTo(IID_TOKEN);
132-
assertThat(context.getAppCheckToken()).isNull();
132+
// AppCheck token needs to be send in all circumstances.
133+
assertThat(context.getAppCheckToken()).isEqualTo(APP_CHECK_TOKEN);
133134
}
134135

135136
@Test
136-
public void getContext_facLimitedUse_whenOnlyAppCheckIsAvailableAndHasError_shouldContainOnlyIid()
137+
public void getContext_facLimitedUse_whenOnlyAppCheckIsAvailableAndHasError()
137138
throws ExecutionException, InterruptedException {
138139
FirebaseContextProvider contextProvider =
139140
new FirebaseContextProvider(
@@ -145,7 +146,8 @@ public void getContext_facLimitedUse_whenOnlyAppCheckIsAvailableAndHasError_shou
145146
HttpsCallableContext context = Tasks.await(contextProvider.getContext(true));
146147
assertThat(context.getAuthToken()).isNull();
147148
assertThat(context.getInstanceIdToken()).isEqualTo(IID_TOKEN);
148-
assertThat(context.getAppCheckToken()).isNull();
149+
// AppCheck token needs to be sent in all circumstances.
150+
assertThat(context.getAppCheckToken()).isEqualTo(APP_CHECK_LIMITED_USE_TOKEN);
149151
}
150152

151153
@Test

firebase-functions/src/main/java/com/google/firebase/functions/FirebaseContextProvider.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ constructor(
8888
if (getLimitedUseAppCheckToken) appCheck.limitedUseToken else appCheck.getToken(false)
8989
return tokenTask.onSuccessTask(executor) { result: AppCheckTokenResult ->
9090
if (result.error != null) {
91-
// If there was an error getting the App Check token, do NOT send the placeholder
92-
// token. Only valid App Check tokens should be sent to the functions backend.
9391
Log.w(TAG, "Error getting App Check token. Error: " + result.error)
94-
return@onSuccessTask Tasks.forResult<String?>(null)
9592
}
93+
// Send valid token (success) or placeholder (failure).
9694
Tasks.forResult(result.token)
9795
}
9896
}

0 commit comments

Comments
 (0)