Skip to content

Firebase token much larger than the device_id 300 character limitation in pnfpb_ic_subscribed_deviceids_web table #25

@WGGlarry

Description

@WGGlarry

In regards to https://github.com/muraliwebworld/push-notification-plugin-for-wordpress-websites/blob/main/pnfpb_push_notification.php,
the 300 character limit for device_id is too small for the tokens I am getting back from Google Firebase, which are typically 1024 characters.

Either I am using a wrong method to have Firebase generate a JWT token or there's another token type that only is <= 300 characters.

I am using the following JS to get my JWT from Firebase:

`
const { google } = require('googleapis');

const MESSAGING_SCOPE = 'https://www.googleapis.com/auth/firebase.messaging';
const SCOPES = [MESSAGING_SCOPE];
const max_token_length = 1024; // localhost's DB's max was increased from Murali's 300 to 1024 in the *_pnfpb_ic_subscribed_deviceids_web table.

function getAccessToken() {
return new Promise(function (resolve, reject) {
const key = require('./service-account.json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function (err, tokens) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}

getAccessToken().then(function (accessToken) {
let token_size = "- Check service account info";

if ( accessToken ) {
	const token_length = accessToken.length;
	const token_too_big = (token_length > max_token_length);
	token_size = (token_too_big ? "WARNING: token length of " : "") + token_length + (token_too_big ? " greater than " + max_token_length + " (" + token_length + ")" : "");
	console.log("Firebase access token: " + accessToken);
	console.log("Token size: " + token_size);
} else {
	console.log("NO Token - fix issues " + token_size);
}

});
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions