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

Add idToken on signIn w/ Apple response #857

Closed
TheNotorius0 opened this issue Jan 8, 2024 · 2 comments
Closed

Add idToken on signIn w/ Apple response #857

TheNotorius0 opened this issue Jan 8, 2024 · 2 comments

Comments

@TheNotorius0
Copy link

Feature request

There is already an opened feature request about this (#551) but since it says fixed by #633 , maybe it has been forgotten.

I think that a lot of us use both the cordova-plugin-firebasex and the Firebase javascript SDK for different things. For example I use this plugin for push notifications, while I use the Firebase javascript SDK for Firestore and the Realtime database (which isn't available using this plugin).

Obviously I need an authenticated user on the Firebase javascript SDK to use the Realtime database, and with Android it has been implemented:

FirebasePlugin.authenticateUserWithGoogle(clientId, function (credential) {

    const credential_web = firebase.auth.GoogleAuthProvider.credential(credential.idToken);

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

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

But on iOS (authenticateUserWithApple) the credential object returned doesn't have the property idToken, so we can't pass it to the signInWithCredential function. Is it possible to add that property to authenticateUserWithApple as well? (see: #633)

dpa99c added a commit that referenced this issue Jan 11, 2024
@dpa99c
Copy link
Owner

dpa99c commented Jan 11, 2024

I've exposed the idToken value in the credential result returned by authenticateUserWithApple on the iOS platform in the commit above.

However it's not possible to return the idToken value in the credential result returned by authenticateUserWithApple on the Android platform, since this uses the oAuth provider flow and so the idToken is not generated/available until signInWithCredential has been called to initiate the oAuth sign-in flow during which the idToken is created. Once the sign-in process has succeeded, the idToken that was used is available in the data returned by getCurrentUser.

@TheNotorius0
Copy link
Author

TheNotorius0 commented Feb 6, 2024

So, I've tried using signInWithCredential 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 gives me this error:

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

Is it possible to have the rawNonce property too in the credential object? Thanks

EDIT: I made a test modifying the plugin, and indeed the sign-in now works, passing the rawNonce. This is the change:

[result setValue:rawNonce forKey:@"rawNonce"]; on line 527, under [result setValue:idToken forKey:@"idToken"];

The Cordova updated and working code is:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants