dpa99c / cordova-plugin-firebasex

Cordova plugin for Google Firebase
MIT License
570 stars 457 forks source link

Add rowNonce on signIn w/ Apple response #867

Open TheNotorius0 opened 3 months ago

TheNotorius0 commented 3 months ago

As a follow up of this issue: https://github.com/dpa99c/cordova-plugin-firebasex/issues/857

I've tried using signInWithCredential of Firebase javascript SDK after signing-in with Apple with the following code:

            FirebasePlugin.authenticateUserWithApple(function (credential) {

                const appleProvider = new firebase.auth.OAuthProvider('apple.com');
                const appleWebCredentials = appleProvider.credential({idToken: credential.idToken});

                firebase.auth().signInWithCredential(appleWebCredentials).then((result) => {

                    showToastShort('Logged-in with Apple');
                });
            });

Unfortunately, it gave me this error:

FirebaseError: Firebase: Nonce is missing in the request. (auth/missing-or-invalid-nonce).

I already manually fixed the issue by modifying the plugin (passing the rawNonce) and it now works. This is what I changed:

[result setValue:rawNonce forKey:@"rawNonce"]; on line 527, under [result setValue:idToken forKey:@"idToken"]; of the AppDelegate+FirebasePlugin file.

The Cordova updated and working code now is:

const appleWebCredentials = appleProvider.credential({idToken: credential.idToken, rawNonce: credential.rawNonce});

Could this change be implemented in an upcoming release? Thank you in advance!