Skip to content

Commit

Permalink
Retrieving verificationId and code from credential object and passsin…
Browse files Browse the repository at this point in the history
…g it along to cordova
  • Loading branch information
manuelsc committed Sep 20, 2018
1 parent 5176a4c commit cdb7894
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,17 @@ public void onVerificationCompleted(PhoneAuthCredential credential) {
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verificaiton without
// user action.
Log.d(TAG, "success: verifyPhoneNumber.onVerificationCompleted - callback and create a custom JWT Token on server and sign in with custom token - we cant do anything");
Log.d(TAG, "success: verifyPhoneNumber.onVerificationCompleted");

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

returnResults.put("verificationId", verificationId);
returnResults.put("code", code);
returnResults.put("instantVerification", true);
} catch (JSONException e) {
} catch(JSONException | IllegalAccessException | NoSuchFieldException e){
Crashlytics.logException(e);
callbackContext.error(e.getMessage());
return;
Expand Down Expand Up @@ -782,7 +786,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
callbackContext.sendPluginResult(pluginresult);
}
};

PhoneAuthProvider.getInstance().verifyPhoneNumber(number, // Phone number to verify
timeOutDuration, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
Expand All @@ -795,6 +799,12 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
}
});
}

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

//
// Firebase Performace
Expand Down

0 comments on commit cdb7894

Please sign in to comment.