From 4c5109816b0d3fa266329bb36ec6fdfb02598ca3 Mon Sep 17 00:00:00 2001 From: sdb9696 Date: Mon, 23 Oct 2023 19:23:45 +0100 Subject: [PATCH] Fix gcm checkin with credentials --- docs/source/conf.py | 2 +- firebase_messaging/fcmpushclient.py | 14 ++++++++------ firebase_messaging/gcm.py | 4 ++++ pyproject.toml | 3 ++- tests/fixtures/android_checkin_response.json | 2 +- tests/fixtures/credentials.json | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9771272..83132f5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -9,7 +9,7 @@ project = "firebase-messaging" copyright = "2023, Steven Beth" author = "Steven Beth" -release = "0.1.0" +release = "0.1.1" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/firebase_messaging/fcmpushclient.py b/firebase_messaging/fcmpushclient.py index caad382..64cc87c 100644 --- a/firebase_messaging/fcmpushclient.py +++ b/firebase_messaging/fcmpushclient.py @@ -695,15 +695,17 @@ def checkin(self, sender_id: int, app_id: str) -> str: self.sender_id = sender_id self.app_id = app_id if self.credentials: - gcm_check_in( - sender_id, + gcm_response = gcm_check_in( + self.credentials["gcm"]["androidId"], self.credentials["gcm"]["securityToken"], log_debug_verbose=self.config.log_debug_verbose, ) - else: - self.credentials = self.register(sender_id, app_id) - if self.credentials_updated_callback: - self.credentials_updated_callback(self.credentials) + if gcm_response: + return self.credentials["fcm"]["token"] + + self.credentials = self.register(sender_id, app_id) + if self.credentials_updated_callback: + self.credentials_updated_callback(self.credentials) return self.credentials["fcm"]["token"] diff --git a/firebase_messaging/gcm.py b/firebase_messaging/gcm.py index 42b8df7..c178438 100644 --- a/firebase_messaging/gcm.py +++ b/firebase_messaging/gcm.py @@ -60,6 +60,10 @@ def gcm_check_in( timeout=2, ) acir = AndroidCheckinResponse() + if resp.status_code != 200: + _logger.error("GCM check failed: %s", resp.text) + return None + acir.ParseFromString(resp.content) if log_debug_verbose: diff --git a/pyproject.toml b/pyproject.toml index 7689c4d..62a4d64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "firebase-messaging" -version = "0.1.0" +version = "0.1.1" description = "FCM/GCM push notification client" authors = ["sdb9696 "] license = "MIT" @@ -17,6 +17,7 @@ classifiers = [ "Environment :: Other Environment", "Intended Audience :: Developers", "Operating System :: OS Independent", + "Programming Language :: Python :: 3.12", "Topic :: Software Development :: Libraries :: Python Modules" ] packages = [ diff --git a/tests/fixtures/android_checkin_response.json b/tests/fixtures/android_checkin_response.json index deaa886..5801f61 100644 --- a/tests/fixtures/android_checkin_response.json +++ b/tests/fixtures/android_checkin_response.json @@ -1,7 +1,7 @@ { "statsOk": true, "timeMsec": "1697711296660", - "androidId": "5096409216052650026", + "androidId": "5678901234567890123", "securityToken": "0123456789012345678", "versionInfo": "Y9B3d2P5mMMSQKri541rkWUVCal3tBg" } \ No newline at end of file diff --git a/tests/fixtures/credentials.json b/tests/fixtures/credentials.json index 55ad057..f4999b1 100644 --- a/tests/fixtures/credentials.json +++ b/tests/fixtures/credentials.json @@ -2,7 +2,7 @@ "gcm": { "token": "XYZ01234zyx:APA91b0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ-01234abcdefghijklmnopqrstuvwxyz", "appId": "abcdef01-ef12-1234-12ef-abcdef012345", - "androidId": "4", + "androidId": "5678901234567890123", "securityToken": "0123456789012345678" }, "keys": {