question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getToken returns some JWT instead of the instance ID

See original GitHub issue

Describe the bug After updating to capacitor v3 and the current version of the fcm plugin, our call to getToken() stopped working. Instead of some FCM token it returns a JSON web token.

To Reproduce Steps to reproduce the behavior:

  1. Setup an app with FCM
  2. Call requestPermissions() and register() on PushNotifications
  3. Call FCM.getToken()

Expected behavior We expected it to return an fcm token which looks like a random string with a colon. e.g. eFznuNk5RsqUaR33qoswb7:APA91… Instead we got a JWT token: jwt.io

Desktop (please complete the following information):

  • OS: Android
  • Browser: capacitor
  • Version: v3

Smartphone (please complete the following information):

  • Device: AVD Emulator - Pixel 3a API 30

Additional context

Ionic:

   Ionic CLI                     : 6.13.1 (/home/---/.npm-packages/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.8.1
   @angular-devkit/build-angular : 12.2.3
   @angular-devkit/schematics    : 12.2.3
   @angular/cli                  : 12.2.3
   @ionic/angular-toolkit        : 4.0.0

Capacitor:

   Capacitor CLI   : 3.2.4
   @capacitor/core : 3.2.4

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res                          : not installed
   native-run (update available: 1.5.0) : 1.4.1

System:

   NodeJS : v15.14.0 (/home/---/.nvm/versions/node/v15.14.0/bin/node)
   npm    : 7.19.0
   OS     : Linux 5.14

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
eljasscommented, Oct 13, 2021

For this reason we use:

PushNotifications.addListener('registration', async ({ value }) => {
  let token = value // Push token for Android

  // Get FCM token instead the APN one returned by Capacitor
  if (Capacitor.getPlatform() === 'ios') {
    const { token: fcm_token } = await FCM.getToken()
    token = fcm_token
  }
  // Work with FCM_TOKEN
})
3reactions
sburnickicommented, Apr 2, 2022

TL;DR: Cause of the issue is the migration of a breaking change in Firebase Android SDK 22.0 that went wrong in 18bb0a0b33bd4ed71b9b990a0153f9d06541003b via #88

Long version: It seems the problem did not arise from Capacitor3 upgrade, but from pull request #88 (precisely: commit 18bb0a0b33bd4ed71b9b990a0153f9d06541003b) where a breaking change in Firebase Android SDK 22.0 was tried to be migrated as documented. However, documentation here is a bit tricky, as migration differs depending on what you needed the token for: identifying the installation or getting an FCM token; seems like the instance id token did both jobs before. So unfortunately the wrong part of the migration guide was chosen: migration to FirebaseInstallations instead of FirebaseMessaging.

My best guess is that they still might be the same but are not guaranteed to be the same? In the end, the migration needs to be done properly to FirebaseMessaging.

Capacitor 3’s push-notification plugin still uses the deprecated FirebaseInstanceId method, which is probably why the suggest to only use SDK 21.0.1 in their docs. But at least this is working, that’s why the workaround mentioned by @eljass works. But I would also really like to see that code updated to use the up-to-date solution based on FirebaseMessaging

Read more comments on GitHub >

github_iconTop Results From Across the Web

FirebaseInstanceId.getInstance().getToken() returns JSON ...
Sometimes when I call FirebaseInstanceId.getInstance().getToken() , it returns the correct String token, but other times it returns a JSON ...
Read more >
How to get an access token with JWT Grant
This topic demonstrates how to generate an access token manually using JSON Web Token (JWT) Grant authentication. Note: Instead of generating the access ......
Read more >
Manage Firebase installations - Google
The Firebase installations service (FIS) provides a Firebase installation ID (FID) for each installed instance of a Firebase app. The Firebase installation ...
Read more >
Microsoft identity platform access tokens
Tokens that are received for a Microsoft API might not always be a JWT and can't always be decoded. For details on what's...
Read more >
Authentication using JWT | Hasura GraphQL Docs
The idea is that your auth server will return JWT tokens, ... If it is using EdDSA instance of Edwards25519, then use Ed25519...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found