Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving verificationId and code from credential object #861

Merged
merged 6 commits into from
Sep 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,24 @@ public void onVerificationCompleted(PhoneAuthCredential credential) {

JSONObject returnResults = new JSONObject();
try {
String verificationId = getPrivateField(credential, "zzfc");
String code = getPrivateField(credential, "zzfd");

returnResults.put("verificationId", verificationId);
returnResults.put("code", code);
String verificationId = null;
String code = null;

Field[] fields = credential.getClass().getDeclaredFields();
for (Field field : fields) {
Class type = field.getType();
if(type == String.class){
String value = getPrivateField(credential, field);
if(value == null) continue;
if(value.length() > 100) verificationId = value;
else if(value.length() >= 4 && value.length() <= 6) code = value;
}
}

returnResults.put("verificationId", verificationId != null ? verificationId : false);
manuelsc marked this conversation as resolved.
Show resolved Hide resolved
returnResults.put("code", code != null ? code : false);
returnResults.put("instantVerification", true);
} catch(Exception e){ // JSONException | IllegalAccessException | NoSuchFieldException
} catch(JSONException e){
Crashlytics.logException(e);
callbackContext.error(e.getMessage());
return;
Expand Down Expand Up @@ -800,10 +811,13 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
});
}

private static String getPrivateField(PhoneAuthCredential credential, String field) throws NoSuchFieldException, IllegalAccessException {
Field credentialField = credential.getClass().getDeclaredField(field);
credentialField.setAccessible(true);
return (String) credentialField.get(credential);
private static String getPrivateField(PhoneAuthCredential credential, Field field) {
try {
field.setAccessible(true);
return (String) field.get(credential);
} catch (IllegalAccessException e) {
return null;
}
}

//
Expand Down