Reputation: 10928
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?
Upvotes: 49
Views: 60115
Reputation: 1
I dont know if that is still relevant. But i faced the same issues for days. I cant really say what it was. But here is what i did.
Cant really what it was. But i tried everything before. Nothing seemed to be working. Maybe this will help someone.
Upvotes: 0
Reputation: 41
I encountered the same issue
errorInfo: {
code: 'messaging/third-party-auth-error',
message: 'Auth error from APNS or Web Push Service'
},
codePrefix: 'messaging'
After digging into the issue I found the missing part Firebase needs the certificate to be uploaded twice (development, production) mine was only uploaded as development. once I upload it as production too everything works
Upvotes: 1
Reputation: 426
I've tried everything in this post, but it didn't work for a week. Finally, I found the mistake and am sharing it.
As a result, @Seph Reed was right. The reason for the Auth error from APNS or Web Push Service error is based on these corrections:
App Store ID
Bundle ID
Team ID
It turned out that the issue was with the Bundle ID.
In Xcode, under Signing & Capabilities, there are multiple places where you can enter the Bundle Identifier.
The topmost Bundle Identifier was left as is, with the environment variable that was automatically generated when the project was created in react-native. That part also needs to be corrected.
The image below shows how it should finally look
Upvotes: 0
Reputation: 2158
Wanted to add in another reason why this might happen with ios specifically. They are upgrading to keys. So if you have certificates it might still work until may 2024 with you are debugging, but when launched it will fail to push the notifications.
in apple dev console Certificates, Identifiers & Profiles->Keys->+ then check apns
in the firebase ios upload that key and you will see a notice it will automatically disable certificates.
Upvotes: 0
Reputation: 273
If everything else fails, try creating new firebase project and setup push notifications for it.
For our purpose we only use firebase to send push notifications so this works. If you use it for anything else, you could separate the push notifications still to separate project and call it via HTTP-requests for example.
For some unknown reason one of our project fails on sending push notifications, it was fixed by re-creating the firebase-project.
Upvotes: 0
Reputation: 64
Double check if you have uploaded your apns key on firebase console. That was my case.
Upvotes: 2
Reputation: 340
I had the same issue. The culprit was lowercase APNs teamId. Changing it to capital solved it.
Upvotes: 0
Reputation: 792
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:
firebase deploy --only
functions
Upvotes: 8
Reputation: 10928
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:
When adding an APNs key (Uploading to Cloud Messaging > APNs Authentication Key):
Upvotes: 47
Reputation: 2520
Did you call admin.initializeApp()
?
There are many official samples.
See:
Upvotes: 0