getToken returns some JWT instead of the instance ID
See original GitHub issueDescribe 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:
- Setup an app with FCM
- Call
requestPermissions()
andregister()
onPushNotifications
- 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:
- Created 2 years ago
- Reactions:10
- Comments:16 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For this reason we use:
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 ofFirebaseMessaging
.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