PyFCM
PyFCM copied to clipboard
Breaking changes in pyfcm 2.1.0 where explicit project_id is set
Summary
This commit adjusted the way the project_id is used when FCMNotification is instantiated:
https://github.com/olucurious/PyFCM/commit/80fec94ce99a70277a33f7983b1f0fdf796ccdee
We run a cloud function which does push notifications in a different project to the firebase project. The service account exists in a different project.
Details
We instantiate FCMNotification like this:
push_service = FCMNotification(
service_account_file=service_account_file,
project_id="firebase-project",
)
That project_id will never be used if you have a service account: https://github.com/olucurious/PyFCM/blob/c94dc6d64e7e33c30b4442a172fb24f2e02f8dd1/pyfcm/baseapi.py#L89
Our service account is in a different project:
{
"type": "service_account",
"project_id": "backend-project",
"private_key_id": "<redacted>",
"private_key": "<redacted>",
"client_email": "<redacted>",
"client_id": "<redacted>",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/sepush-push-topics%40sepush-backend.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
Recommendation
Adjust this code: https://github.com/olucurious/PyFCM/blob/c94dc6d64e7e33c30b4442a172fb24f2e02f8dd1/pyfcm/baseapi.py#L89
To be:
project_id = self._project_id or getattr(self.credentials, "project_id", None)