Flutter app crashing without exception when calling FacebookAuth.instance.login() - firebase

I've followed the tutorial for implementing the Facebook Login from
https://firebase.flutter.dev/docs/auth/social/
Which is the official documentation, my function is literally just:
facebookLogin() async
{
final LoginResult loginResult = await FacebookAuth.instance.login(); // final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken!.token);
// var credentials = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}
I've commented the following function to isolate the problem.
On the console i get the following:
Performing hot reload...
Reloaded 1 of 1031 libraries in 908ms.
Lost connection to device.
And no exceptions nor errors.
Has anyone faced the same problem before?
I'm using:
flutter_facebook_auth: ^4.1.1
firebase_core: ^1.13.1
firebase_auth: ^3.3.9
In my pubspec.yaml
Is there any way to debug this problem further and find the problem?

Please ensure that you followed the setup steps one by one, and they are:
Ensure the "Facebook" sign-in provider is enabled on the Firebase Console. with the Facebook App ID and Secret set
follow the steps in the plugin (flutter_facebook_auth) documentation to ensure that both the Android & iOS Facebook SDKs have been initialized correctly
Please note that firebase flutterfire uses: flutter_facebook_auth: '^3.5.0' in their documentation and the latest version of that package 4.1.1 untill this day (3/4/2022)

It can be an issue with info.plist configuration for flutter deep-linking.
Did you setup it for your app?
https://docs.flutter.dev/development/ui/navigation/deep-linking
to be more specific you should have only one CFBundleURLTypes section in your info.plist

I had exactly the same problem. Here is how I solved.
In Info.plist, I had 2 sessions called "CFBundleURLTypes", one for Facebook Login, and another one for Google login. Apparently you can only have one CFBundleURLTypes session.
So the solution was to merge everything into a single CFBundleURLTypes session.

Related

Expo Push Notification Unable to retrieve the FCM server key for the recipient’s app. Make sure you have provided a server key as directed…

SDK Version: 40
Platforms(Android/iOS/web/all): Android
I already have setted the expo push:android:show
error return me:
Click to see error img
If I click on button just have no returns
I’m just using the example code available on Push Notifications Overview - Expo Documentation 1
setted expo push:android:show and
fcm,firebase,push,google-services.json
look:
Cick to see what I setted
I installed the expo dependecies before expo ejected.
I setted the Firebase app name com.myname.testpush as the AndroidManifest package name as well.
“dependencies”: {
“expo”: “~40.0.0”,
“expo-status-bar”: “~1.0.3”,
“react”: “16.13.1”,
“react-dom”: “16.13.1”,
“react-native”: “~0.63.4”,
“react-native-web”: “~0.13.12”,
“expo-notifications”: “~0.8.2”,
“expo-permissions”: “~10.0.0”,
“expo-splash-screen”: “~0.8.1”,
“expo-task-manager”: “~8.5.0”,
“expo-updates”: “~0.4.0”,
“expo-constants”: “~9.3.0”,
“#react-native-firebase/app”: “^10.5.0”,
“react-native-gesture-handler”: “~1.8.0”,
“react-native-reanimated”: “~1.13.0”,
“react-native-screens”: “~2.15.0”,
“react-native-unimodules”: “~0.12.0”
},
“devDependencies”: {
“#babel/core”: “~7.9.0”,
“babel-jest”: “~25.2.6”,
“jest”: “~25.2.6”,
“react-test-renderer”: “~16.13.1”
},
posted on expo as well: https://forums.expo.io/t/push-notification-unable-to-retrieve-the-fcm-server-key-for-the-recipients-app-make-sure-you-have-provided-a-server-key-as-directed/48529
expo push:android:show (it wasn't configured for me)
then expo push:android:upload --api-key , replacing with the string you just copied. (to get the token look at https://docs.expo.io/push-notifications/using-fcm/#uploading-server-credentials)
Adding on here: I was totally confused by firebase's new cloud messaging api and the documentation.
You have to use firebase legacy cloud messaging to get a Server Key. Other than that - documentation and uploading that server key worked great as described by others.
Screenshot showing:
Solved on Expo Forum (https://forums.expo.io/t/push-notification-unable-to-retrieve-the-fcm-server-key-for-the-recipients-app-make-sure-you-have-provided-a-server-key-as-directed/48529/2)
#adamjnav creating a new project I could see that I forgot of set my experienceId: "#myexpouser/myproject"
and my app.json android: { …, “useNextNotificationsApi”: true, “adaptiveIcon”:"… }

Flutter Firebase Dynamic Link not working on new ios app install

I am trying to handle dynamic links within my flutter app and they work perfectly when the app is already installed. The link works fine regardless if the app is open or closed in the background. However when I try to use a link when the app is not installed I am properly brought to the app store, but then once I open the app from within the app store after the install completes it just opens the app and my dynamic link functionality never executes.
My dynamic link is similar to this:
https://startingxi.page.link/?link=https://url-redacted/game/gameId&apn=myapn&isi=mysi&ibi=myibi&st=new%20team%20vs%20&sd=1%20-%202&efr=1
I have tried with both efr=1 and without that.
My flutter code:
#override
void initState() {
super.initState();
initDynamicLinks();
futureInitState = initStateAsync();
}
Future<void> initDynamicLinks() async {
final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
final Uri deepLink = data?.link;
await processDeepLink(deepLink);
FirebaseDynamicLinks.instance.onLink(onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
await processDeepLink(deepLink);
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
displayFlushBar('$e.message');
});
}
I have tried putting the initDynamicLinks within my futureInitState which is part of my FutureBuilder which does other async stuff at startup. Any help would be appreciated. I'm not sure how to debug this problem and this is my first ios/app dev experience so I'm not sure if there are some logs on the ios device that may help? But at the moment it seems as though I need to deploy to production and get my change live in the app store before I can test anything and that seems less than ideal. But since the dynamic link works in the other use cases I'm stumped on troubleshooting.
Thanks!
Common troubleshooting steps for issues on opening Firebase Dynamic Links after app install is to make sure that value of the ibi parameter matches the app's Bundle ID.
For Google-provided *.page.link domains: in the Capabilities tab of the app's Xcode project, Associated Domains shoudld be enabled, and the following is added in the Associated Domains list: applinks:{your_dynamic_links_domain}.
Also, verify that the AASA of your FDL https://{your_dynamic_links_domain}/apple-app-site-association contains an entry for your app. Verify "appID":"{team-id}.{bundle-id}" values are correct for your app
If these steps didn't work, it's best to reach out to Firebase Support as they have the tools to diagnose deeper into this issue.

Firebase Error: Auth error from APNS or Web Push Service

After running the following line in node-js:
import * as admin from "firebase-admin";
import * as serviceAccount from "../../firebase_service_account_key.json";
const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount as any),
databaseURL: "https://my-app-path.firebaseio.com"
});
admin.messaging().send({
token: "known-good-token",
notification: {
title: "Test Push Note",
body: "Here is some text"
}
});
I'm getting the error:
Error: Auth error from APNS or Web Push Service
Raw server response:
"{
"error":{
"code":401,
"message":"Auth error from APNS or Web Push Service",
"status":"UNAUTHENTICATED",
"details"[
{
"#type":"type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode":"THIRD_PARTY_AUTH_ERROR"
},
{
"#type":"type.googleapis.com/google.firebase.fcm.v1.ApnsError",
"statusCode":403,
"reason":"InvalidProviderToken"
}
]
}
}"
I've added an "APNs Authentication Key" to my ios project under the Settings > Cloud Messaging section of Firebase. I've also properly downloaded and imported my service account json file.
In terms of research, I've tried looking up the errors.
For the InvalidProviderToken error, this answer seems to indicate I'm using an old token. This is totally possible, but the logs on my app and database appear to match, so it seems off.
As for the THIRD_PARTY_AUTH_ERROR, google gave me no hits. The closest thing I found was this, and the following text might be the culprit (EDIT: it's not the issue):
auth/unauthorized-domain
Thrown if the app domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.
Does anyone have anymore details on this error which might help me get to the bottom of it?
This error arises if your app setup for iOS has an error in any one of the following:
Found in Settings > General > Your Apps > iOS Apps:
App Store ID
Bundle ID
Team ID
When adding an APNs key (Uploading to Cloud Messaging > APNs Authentication Key):
Team ID (should auto set based off ios app info above)
Key Id (often is in the name of the key, best to grab when creating it)
Everything worked for me the other day, so all setup was fine. But today I got this error.
Here's what solved it for me:
Revoked APNs Key
Created new one and downloaded it
Deleted old one and Uploaded it to Firebase Dashboard / Settings /
Cloud Messaging
Gone to Settings / Service Accounts and generated new private key
Added it to my Cloud Functions project (renamed it to
service-account.json in my case)
Saved the files and deployed the functions: firebase deploy --only
functions
Did you call admin.initializeApp()?
There are many official samples.
See:
https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js#L20
https://github.com/firebase/functions-samples/tree/master/fcm-notifications
https://github.com/firebase/functions-samples
https://github.com/firebase/quickstart-js/tree/master/messaging
I had the same issue. The culprit was lowercase APNs teamId. Changing it to capital solved it.
Double check if you have uploaded your apns key on firebase console. That was my case.

Invalid token because of wrong audience?

I just made a firebase project, installed the pods and got the googleplist in, configured it in the app delegate, and set it up exactly like I have other projects.
For my pods, I've got exactly what I have in my main other project :
pod 'Firebase/Core’
pod ‘Firebase/Auth’
pod ‘Firebase/Database’
When I run this code :
let ref = FIRDatabase.database().reference()
ref.setValue("hello")
I get an error that pops up like 50 times that says :
MyProjectName[209384092:9028304928034randomnumbers] [FirebaseDatabase] Autentication failed: Invalid_token (audience was project 'a random project from my firebase console' but should have been project 'myProjectName'.
I thought maybe I had done something really goofy at first, so I deleted my project entirely and reinstalled a new google.plist and redid everything, but the only thing that has changed is now I'm just getting a different random project from my firebase project list.
What's goin' on here?
I had the same error as you got, but it only occurred in simulator.
To fix this issue I had to reset my simulators content and settings.
If anyone is experiencing this issue on an actual iPhone device rather than the simulator the root cause of this issue is provided in another SO thread:
Swift/Firebase Database invalid token error
It looks Firebase plan to address it in a future SDK update but to resolve it for now you must sign-out + invalidate your Firebase Database session in your 'old' project first:
NSError *error;
[[FIRAuth auth] signOut:&error];
if (error) {
ELog(#"Firebase Logout failed: %#", error.localizedDescription);
}
Your 'new' project should then now function as expected.
Maybe you are not taking the correct apiKey and authDomain. Go to Firebase, select the project go to Authentication and then Web Setup and see if the apiKey and authDomain are the same keys that you are using in the firebase.initializeApp({});

FCM getting MismatchSenderId

I have an application that uses Google FCM for sending push notifications.
When i send a push notification to a group of users, i get a response of MismatchSenderId for some of them. Even though, all users have the exact same application. How can some of the users get a success response and others get a MismatchSenderId?
I have researched a lot and made sure I have added all prerequisites that FCM needs.
Any suggestions?
EDIT:
Sample response:
{"multicast_id":5340432438815499122,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
EDIT 2:
Here is the server side sending code (PHP):
$fields = array
(
'to' => $token,
'data' => $data
);
$headers = array
(
'Authorization: key=AIza**************************',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields) );
curl_exec( $ch );
curl_close( $ch );
UPDATE:
It seems that the issue has been resolved with the SDK updates. I am using now the latest com.google.firebase:firebase-messaging:9.6.1, I don't get "MismatchSenderId" anymore.
Firebase has upgraded their server keys to new version.
Use new keys instead of old one.
go to settings->project settings->cloud messaging tab
I found this solution:
First I check server key is correct or not it was correct which is
like AIzaXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Then I check Sender Id like 79XXXXXXXX it was also correct.
Main issue was in device_ID(UDID) to whom I have to send the notification. Actually DeviceId we got on android side in FCM is different than GCM. You can't use GCM created DeviceId in FCM.
Just an FYI. I was running into this error, even though I swear the android app I was testing was built with the latest/greatest google-services.json file and I could send from the FCM console to the app.
I rebuilt the app after doing a Clean Project and now I can send to the app with the FCM token it registers. So, maybe try a clean rebuild before beating your head against the wall for too long.
THIS WORKED FOR ME:
CHECK WHICH FIREBASE PROJECT YOUR CURRENT ANDROID PROJECT IS LINKED TO AND USE
Server Key FROM THAT PROJECT.
I was using Server key from a different firebase project(say Project 2). I used the same server key as linked with my android project(Say Project 1) and it worked. In my experience, using one firebase app for one entire android project seemed to fix the problem.
In my case, I just was mistaking about project credentials: using google-services.json from one project, and server key from another.
We spent hours and hours to resolve this issue. What we found that token was being generated using different FCM account settings (google-services.json) and notification was being set using different FCM account.
When we synced both it worked like a charm.
My problem was solved by entering the correct key as shown below.
Copy Server key like this picture
And then copy this code in post man like this picture
and Body is row like this picture
NOTE:
You must add key= before Server key in header
Make sure you enter the header keys correctly (Authorization =
"key=..." and ContentType = "application/json")
You have sent the request to the correct address
(https://fcm.googleapis.com/fcm/send and Post method)
I cross verified all the credentials
Added new server key and deleted old one
Downloaded google-services.json again
Nothing solved the issue
Then I just clean the project and then rebuild the project.After that it's working fine
I found that the senderId is different from the project number in the FCM console
so I re-downloaded google-services.json and everything works fine
Make sure you remove all the Parse code from your app (libraries, receivers in AndroidManifest, etc). I found that intermittently push notifications were not working. From my observations, it would work on fresh installs but not app updates from the play store.
I believe something internal to Parse was conflicting with FCM (Parse uses GCM, so I'm guessing it had to do with using GCM and FCM simultaneously). As soon as I ripped out all the Parse receivers and libraries, things worked great.
Actually there are many reasons for this issue.
Mine was because of Invalid token passed.
I was passing same token generated from one app and using same token in another app.
Once token updated , it work for me.
I spent hours on this and finally figured it out. This problem happens if service account your sender application is using differs from the service account your receiver is using.
You can find out your receiver service account via Firebase -> Project Overview -> Project Settings -> Service Accounts and generate a new key and use that key when you are initializing your FirebaseApp in the sender:
FileInputStream serviceAccount = new FileInputStream("YOUR_PATH_TO_GENERATED_KEY.json");
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(googleCredentials).build();
firebaseApp = FirebaseApp.initializeApp(options);
This initialization need to be done once before you send push notifications.
In my case, I had done everything correctly and I still had this problem. I had made some changes in the "google-services.json" used in the receiver app and I noticed AndroidStudio was not using my new file. The solution was so simple:
AndroidStudio -> Build -> Clean Project and Build -> Rebuild Project
For eliminate this error for mismatch sender Id In fcm
{"multicast_id":7751536172966571167,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
there is error occured,
So we required first, In FCM, register Application e.g MyDemoApplication
After that FCM will generate server key i.e AIzaSyB9krC8mLHzO_TtECb5qg7NDZPxeG03jHU and sender Id i.e 346252831806 these format like these.
After In Android Studio, our project is connect to these FCM created project i.e MyDemoApplication
And most important step is there required to device token or registration id. These token must created in Android Studio..
After that using Sender Id and API key in web API project u will be definitely getting notification
I had the same issue in my react-native - node.js project.
I wanted to send notifications in android.
Everything was set-up and working fine (i.e. I was able to send notifications from node.js and receive notifications on android device).
After a few days, I had to use a different firebase account, so I changed the google-services.json file in my project's android/app folder and rebuilt the project. But, when I tried sending notification from my server once again, I got an error -
{.............
errorInfo: {
code: 'messaging/mismatched-credential',
message: 'SenderId mismatch'
},
codePrefix: 'messaging'
}
Solution:
the XML file at the location -
app/build/generated/res/google-services/{build_type}/values/values.xml was not getting automatically updated according to new google-services.json.
It still consisted of old values from my previous google-services.json file. I had to change values.xml file manually.
This is how app/build/generated/res/google-services/{build_type}/values/values.xml file look (You need to change it manually if it does not get updated automatically according to google-services.json)-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<! -- Present in all applications -->
<string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>
<! -- Present in applications with the appropriate services configured -->
<string name="gcm_defaultSenderId" translatable="false">1035469437089</string>
<string name="default_web_client_id" translatable="false">337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
<string name="ga_trackingId" translatable="false">UA-65557217-3</string>
<string name="firebase_database_url" translatable="false">https://example-url.firebaseio.com</string>
<string name="google_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="project_id" translatable="false">mydemoapp</string>
</resources>
You can refer to these links:
https://firebase.google.com/docs/projects/multiprojects
Processing the JSON file: https://developers.google.com/android/guides/google-services-plugin#processing_the_json_file.
I got this Error after I added more Product Flavours to my current App,
it seems like it uses the package name to generate the FCM Token, so to reslove the issue I have to add an app for eatch Flavour with it's corresponding PackageName, and update the google-services.json file with the latest generated one wich include Client info for each Flavour(Package Name).
check gcm_sender_id in manifest.json
If mismatch - correct, but you need make new subscribers for new sender Id.
Exists subscribers break.
As per response "MismatchSenderId", this is a mismatch between FireBase and your local "google-services.json", you have to make sure that both manifests matches
In FireBase console you go to "YourProject > Project OverView > Cloud Messaging" you'll see the "SenderID" which MUST match with the "google-services.json" in your Android project.
Best thing you can do is download the final json file from "General" tab and place it in your project.
I had the same error while trying to send push notificaion. Get the updated google-services.json file and replaced with it. Worked for me.
I was trying to send notification using the fcm api "https://fcm.googleapis.com/fcm/send" from postman. Server key was ok and token was pasted fine but was still getting error "MismatchSenderId".
Then introduced the follwoing dependency in the gradle file on android side.
implementation platform('com.google.firebase:firebase-bom:25.12.0')
and it started receiving notifications on the device
Make sure that your "package_name" in the google-service.json file is your applicationId from build.gradle(app) file.
"client_info": {
"mobilesdk_app_id": "",
"android_client_info": {
"package_name": "" // -> your applicationId
}
}
I found the reason for this problem after 5 years of using Firebase.
Of course, this happened to me when I tried to get a new google-services.json file for old projects.
When you receive the new file, you must use the latest version of google-services.
classpath 'com.google.gms:google-services:$.$.$'
Updating firebase initialization works for me..
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);
</script>
For me the problem was that I was using the phonegap-plugin-push in cordova, testing the app with the phonegap app.
The problem with this is that for some reason with this plugin, the phonegap app intercepts it and returns a dummy registration key, no matter what sender ID you have.
So to make it work (as long as you have all your keys right) is to test your program some other way, with an emulator, or android emulation via usb. And your keys will match.
Hopefully this saves someone some time.
your probably doing whwat i was doing. GCM token is not the same as FCM anymore. check if your pulling the GCM token ID instead of FCM. just override FirebaseInstanceIdService & ensure your getting the right ID. i thought at one point they were the same but now there not. i logged a test and saw. after you do that also update google-services.json like others say as a safety.
I wasted days on this.
In my case, I followed this blog to use Postman and get the mismatchsenderid error. Previously, I was getting messaging/mismatched-credential, and people reported that their client app used multiple projects.
However, for me, I have one-to-one, a web app and a project. BUT, I host all apps via ng serve on default port 4200. So regardless of what project / app pair I was developing on, I would always get the same token from my client web app using AngularFireMessaging.requestToken - this token was always the token created on my first ever run of a firebase app in development.
As a work around, I start different apps / projects on different ports and get proper tokens for respective projects.
Note: I had truncated the first part of the FCM token (before :) and the error was MismatchSenderId
Fixed my script and now everything works fine.
In my case someone had deleted APN SSL Certificates for my app in Apple development portal.
I needed to create new certificates: Identifiers / My AppId / Push Notifications / Edit.
Then I uploaded them to the Firebase project from console: Project Settings / Cloud Messaging / iOS app configuration / APNs Certificates.
This solved the problem.
In my case it was very simple. I was pulling the wrong registrationId from the database. After I pulled the correct Id, it worked.
I had big trouble figuring out why I was getting a "MismatchSenderId" status.
I added the gms dependency in the root build.gradle but my error was actually not applying the gms plugin in the app build.gradle.
If you have don't have this line in the app build.gradle, this could be the reason why the notification are not working:
apply plugin: 'com.google.gms.google-services'
I have noticed that when a device id is created in GCM you cannot send push messages through FCM using the new server key, you have to use the old API-key.

Resources