bug: Twitter auth provider cannot transition from native auth to Firebase JS SDK auth
See original GitHub issuePlugin(s):
@capacitor-firebase/authentication@0.3.0
Platform(s): iOS
Current behavior:
Twitter Auth Provider cannot transition from native auth to Firebase JS SDK auth.
The FirebaseAuthentication.signInWithTwitter()
method returns no result.credential.accessToken
nor result.credential.secret
(both undefined
). Thus I’m unable to get the OAuthCredential
using const nativeCredential = TwitterAuthProvider.credential(result.credential?.accessToken, result.credential?.secret)
in order to perform the authentication on the web layer with signInWithCredential(auth, nativeCredential)
.
Expected behavior:
Twitter auth provider returns credential.accessToken and credential.secret (like it does on Android) and we can use those to perform the authentication on the web layer with signInWithCredential(auth, nativeCredential)
.
Steps to reproduce: I followed the steps mentioned in the How to use this plugin with the Firebase JavaScript SDK guide.
Related code: But as the Twitter example is missing I used the following (based on the other examples)
const signInWithTwitter = async () => {
// 1. Create credentials on the native layer
const result = await FirebaseAuthentication.signInWithTwitter();
// 2. Sign in on the web layer using the access token
const credential = TwitterAuthProvider.credential(result.credential?.accessToken, result.credential?.secret);
const auth = getAuth();
await signInWithCredential(auth, credential);
};
Other information: My project is working fine on Android and the web. On iOS I got these errors on the Safari DevTools console:
- FirebaseError: Firebase: Error (auth/argument-error).
- null is not an object (evaluating ‘credential._getIdTokenResponse’)
This is the way I’m initializing the @angular/fire
library in my NgModule according to this comment and this comment:
...
provideFirebaseApp(() => {
const app = initializeApp(environment.firebase);
if (Capacitor.isNativePlatform()) {
initializeAuth(app, {
persistence: indexedDBLocalPersistence
});
}
return app;
}),
provideAuth(() => getAuth())
...
I also tried this alternate init with no luck. I don’t believe this is the cause anyway:
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence
});
} else {
return getAuth();
}
}),
Capacitor doctor:
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 3.5.1
@capacitor/core: 3.5.1
@capacitor/android: 3.5.1
@capacitor/ios: 3.5.1
Installed Dependencies:
@capacitor/cli: 3.5.1
@capacitor/ios: 3.5.1
@capacitor/android: 3.5.1
@capacitor/core: 3.5.1
[success] iOS looking great! 👌
[error] Missing <manifest package=""> attribute in app/src/main
Issue Analytics
- State:
- Created a year ago
- Comments:12 (7 by maintainers)
Okay, i found the issue and fixed it. You can give it a try if you want:
I will release this fix in a few days.
Thank you for the report @agustinhaller !
@agustinhaller Unfortunately I could not gather more information. I created an issue in the
firebase-ios-sdk
repo: https://github.com/firebase/firebase-ios-sdk/issues/9878