@@ -57,6 +57,8 @@ public class NetworkClient {
57
57
"https://firebaseappcheck.googleapis.com/v1beta/projects/%s/apps/%s:exchangeDebugToken?key=%s" ;
58
58
private static final String PLAY_INTEGRITY_EXCHANGE_URL_TEMPLATE =
59
59
"https://firebaseappcheck.googleapis.com/v1/projects/%s/apps/%s:exchangePlayIntegrityToken?key=%s" ;
60
+ private static final String PLAY_INTEGRITY_CHALLENGE_URL_TEMPLATE =
61
+ "https://firebaseappcheck.googleapis.com/v1/projects/%s/apps/%s:generatePlayIntegrityChallenge?key=%s" ;
60
62
private static final String CONTENT_TYPE = "Content-Type" ;
61
63
private static final String APPLICATION_JSON = "application/json" ;
62
64
private static final String UTF_8 = "UTF-8" ;
@@ -119,6 +121,29 @@ public AppCheckTokenResponse exchangeAttestationForAppCheckToken(
119
121
throw new FirebaseException ("Too many attempts." );
120
122
}
121
123
URL url = new URL (String .format (getUrlTemplate (tokenType ), projectId , appId , apiKey ));
124
+ String response = makeNetworkRequest (url , requestBytes , retryManager );
125
+ return AppCheckTokenResponse .fromJsonString (response );
126
+ }
127
+
128
+ /**
129
+ * Calls the App Check backend using {@link HttpURLConnection} in order to generate a challenge
130
+ * nonce for the Play Integrity attestation flow.
131
+ */
132
+ @ NonNull
133
+ public String generatePlayIntegrityChallenge (
134
+ @ NonNull byte [] requestBytes , @ NonNull RetryManager retryManager )
135
+ throws FirebaseException , IOException , JSONException {
136
+ if (!retryManager .canRetry ()) {
137
+ throw new FirebaseException ("Too many attempts." );
138
+ }
139
+ URL url =
140
+ new URL (String .format (PLAY_INTEGRITY_CHALLENGE_URL_TEMPLATE , projectId , appId , apiKey ));
141
+ return makeNetworkRequest (url , requestBytes , retryManager );
142
+ }
143
+
144
+ private String makeNetworkRequest (
145
+ URL url , @ NonNull byte [] requestBytes , @ NonNull RetryManager retryManager )
146
+ throws FirebaseException , IOException , JSONException {
122
147
HttpURLConnection urlConnection = createHttpUrlConnection (url );
123
148
124
149
try {
@@ -163,7 +188,7 @@ public AppCheckTokenResponse exchangeAttestationForAppCheckToken(
163
188
+ httpErrorResponse .getErrorMessage ());
164
189
}
165
190
retryManager .resetBackoffOnSuccess ();
166
- return AppCheckTokenResponse . fromJsonString ( responseBody ) ;
191
+ return responseBody ;
167
192
} finally {
168
193
urlConnection .disconnect ();
169
194
}
0 commit comments