FirebaseMessaging notification with Flutter: SenderId mismatch 403 PERMISSION_DENIED

I can’t push notifications with my api express js to my device (android & ios)

I read all the documentation about https://firebase.google.com/docs/cloud-messaging/migrate-v1 and some others documentation talking about it.

I followed these instructions to get simple notifications: https://firebase.google.com/codelabs/firebase-fcm-flutter#0

I created a service account for my app and fcm by following theses instructions:
https://help.emarsys.com/hc/en-us/articles/18224997987602-Android-integration-Creating-a-Google-service-account-to-enable-push-notifications

Before the migrations, my notifications were working.
I tried to update it but it bug.

API

  • version: v20.11.1

packages:

  • “firebase-admin”: “^11.0.0”,
  • “google-auth-library”: “^8.9.0”,

Flutter

  • version: 3.22.3

packages:

  • firebase_core: ^2.32.0
  • firebase_analytics: ^10.10.7
  • firebase_messaging: ^14.9.4

Flutter:

class TestFCM {
  static void init() async {
    final messaging = FirebaseMessaging.instance;

    final settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    if (kDebugMode) {
      print('Permission granted: ${settings.authorizationStatus}');
    }
    String? token = await messaging.getToken();
    print('token = $token');
  }
}

I print token to get it and test in my api like so:

API:

const { GoogleAuth } = require('google-auth-library');

const FLUTTER_NOTIFICATION_CLICK = 'FLUTTER_NOTIFICATION_CLICK';

//Here i put my serviceAccountPath
const serviceAccountPath = '';

const auth = new GoogleAuth({
  keyFilename: serviceAccountPath,
  scopes: ['https://www.googleapis.com/auth/firebase.messaging'],
});

const getAccessToken = async () => {
  const client = await auth.getClient();
  const token = await client.getAccessToken();
  return token.token;
};

const admin = require('firebase-admin');

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: process.env.databaseURL,
});

const sendMessage = async (message) => {
  const accessToken = await getAccessToken();

  try {
    const response = await fetch(
      'https://fcm.googleapis.com/v1/projects/odopassdb-test/messages:send',
      {
        method: 'POST',
        headers: {
          Authorization: `Bearer ${accessToken}`,
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ message }),
      },
    );

    const responseData = await response.json();
    console.log('response data', responseData);
    console.log('response details', JSON.stringify(responseData.error.details));
    return responseData;
  } catch (error) {
    console.error('error notification', error);
  }
};

// Here i put my fcmToken getted from the app
const fcmToken = '';

const message = {
  data: {
    title: 'title',
    body: 'body',
    click_action: FLUTTER_NOTIFICATION_CLICK,
    screen: '',
  },
  token: fcmToken,
};

sendMessage(message);

In commented section i enter my value.
I generated the serviceAccount via firebase. I verified senderId, it is correct.
However it failed and return this error:

response data {
  error: {
    code: 403,
    message: 'SenderId mismatch',
    status: 'PERMISSION_DENIED',
    details: [ [Object] ]
  }
}
response details [{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"SENDER_ID_MISMATCH"}]

The API V1 on firebase is enabled:
Firebase Cloud Messaging API (V1)Enabled

Also the legacy is enabled but it looks like i cannot disabled this, and if it use it, it say deprecrated endpoint (when i was using old package of firebase messaging) so it shouldn’t be the error.

How can i resolve it please ?

Have a nice day!

  • Use API V1 to test
  • Recreate an account with https://help.emarsys.com/hc/en-us/articles/18224997987602-Android-integration-Creating-a-Google-service-account-to-enable-push-notifications but it didn’t changed the serviceAccount key.

Recognized by Google Cloud Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật