in Fido/app/src/main/java/com/fido/example/fido2apiexample/GAEService.java [298:335]
public String getSignResponseFromServer(AuthenticatorAssertionResponse response) {
Log.d(TAG, "getSignResponseFromServer");
try {
if (fido2Service == null) {
return null;
}
JSONObject responseJson = new JSONObject();
String clientDataJSON = new String(response.getClientDataJSON(), "UTF-8");
String authenticatorData = BaseEncoding.base64().encode(response.getAuthenticatorData());
String credentialId = BaseEncoding.base64Url().encode(response.getKeyHandle());
String signature = BaseEncoding.base64().encode(response.getSignature());
responseJson.put(KEY_CLIENT_DATA_JSON, clientDataJSON);
responseJson.put(KEY_AUTHENTICATOR_DATA, authenticatorData);
responseJson.put(KEY_CREDENTIAL_ID, credentialId);
responseJson.put(KEY_SIGNATURE, signature);
// insert sessionId for the authenticated credential ID into result data in JSON format,
// and pass it back to server.
String sessionId = sessionIds.get(BaseEncoding.base64Url().encode(response.getKeyHandle()));
responseJson.put(KEY_SESSION_ID, sessionId);
List<String> signResponseContent =
fido2Service.processSignResponse(responseJson.toString()).execute().getItems();
if (signResponseContent == null || signResponseContent.isEmpty()) {
Log.i(TAG, "signResponseContent is null or empty");
} else {
Log.i(TAG, "signResponseContent " + signResponseContent.get(0));
JSONObject credential = new JSONObject(signResponseContent.get(0));
// return string value of the authenticated credential
return credential.toString();
}
} catch (IOException | JSONException e) {
Log.e(TAG, "Error processing sign response", e);
}
return null;
}