It seems you are encountering a 401 Unauthorized error when trying to send notifications from Azure Notification Hubs (ANH) using Firebase Cloud Messaging (FCM). Here are some steps to troubleshoot and ensure everything is set up correctly:
- Check FCM Server Key: Make sure that the server key you are using in your Azure Notification Hub configuration is correct and matches the one from your Firebase project. This key is essential for authenticating requests to FCM.
- Verify Token Registration: Ensure that the FCM token you are using is correctly registered with the Notification Hub. You can check this in the Azure portal to confirm that the token is listed under the registered devices.
- Use FCM V1 API: Since you mentioned that you have set up Google (FCM V1) in ANH, ensure that your payload is correctly formatted for FCM V1. The payload you provided seems to be in the correct format, but double-check for any syntax issues.
- Check Permissions: Ensure that the service account associated with your FCM project has the necessary permissions to send messages. You might need to check the IAM settings in the Google Cloud Console.
- Test with a Simple Payload: Sometimes, complex payloads can cause issues. Try sending a simpler notification payload to see if that works:
{"message": {"notification": {"title": "Test Notification", "body": "This is a test."}}} - Review Logs: Check the logs in both Azure and Firebase to see if there are any additional error messages that could provide more context on the
401 Unauthorizederror.
If after checking these points you still face issues, consider reaching out to Azure support for more detailed assistance.
References: