Firebase Error: Auth error from APNS or Web Push Service

17,815

Solution 1

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

enter image description here

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)

enter image description here

Solution 2

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:

  1. Revoked APNs Key
  2. Created new one and downloaded it
  3. Deleted old one and Uploaded it to Firebase Dashboard / Settings / Cloud Messaging
  4. Gone to Settings / Service Accounts and generated new private key
  5. Added it to my Cloud Functions project (renamed it to service-account.json in my case)
  6. Saved the files and deployed the functions: firebase deploy --only functions

Solution 3

Did you call admin.initializeApp()?

There are many official samples.

See:

Share:
17,815
Seph Reed
Author by

Seph Reed

This universe seems to run out of things to offer much less quickly with technology around. I think it may be our only way to remain entertained indefinitely. See my projects at http://SephReed.me

Updated on June 06, 2022

Comments

  • Seph Reed
    Seph Reed almost 2 years

    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?

  • Seph Reed
    Seph Reed almost 5 years
    I did indeed call the initializeApp() function. I'll check these links monday and see if they contain anything different from what I have.
  • Seph Reed
    Seph Reed almost 5 years
    While your answer is not correct, I can not reclaim a bounty, so it's free reputation. Congrats,
  • Frank
    Frank almost 5 years
    As an additional comment (b/c it took me a couple minutes to figure this out) you need to upload the APNs key you generate to Cloud Messaging => APNs Authentication Key
  • Jerry Chen
    Jerry Chen almost 5 years
    hi, are your requests always sent failed or just few of them? i got the similar issue.
  • Rebar
    Rebar over 4 years
    Got the similiar issue and on my server it worked all day and now it won't. I did all the steps above, but got the error
  • chenop
    chenop about 4 years
    this post ends 3-4 days of desperately trying to display notifications for IOS with firebase in react-native - thank you sir you are an angel
  • Jasper Kuperus
    Jasper Kuperus over 3 years
    In my specific case, I just renamed my bundle ID, but forgot to do that in Xcode. So the app ID, keys and APNs config in Firebase, Google Services file were all set up, but I only had to update the bundle ID in Xcode to make it work.
  • MadMac
    MadMac about 3 years
    Expanding on @Franks comment. If you have more than one ios app then you will need to upload the APNs Auth Key for each app here console.firebase.google.com/u/1/project/hivepass-dev/setting‌​s/…
  • MadMac
    MadMac about 3 years
    It a real shame there is a hard limit of 30 apps per Firebase project as I have plans for over 100 apps. This means I will need to split my project in 4+ projects.
  • justchris
    justchris about 2 years
    The exact same thing happened to me. Everything was working, then suddenly iOS notifications stopped working. Did your steps above and they fixed the problem. This is very strange. Did you ever figure out why this happened to you?