Skip to content

Commit

Permalink
Fix gcm checkin with credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
sdb9696 committed Oct 23, 2023
1 parent 447d379 commit 4c51098
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions firebase_messaging/fcmpushclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 4 additions & 0 deletions firebase_messaging/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand All @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/android_checkin_response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"statsOk": true,
"timeMsec": "1697711296660",
"androidId": "5096409216052650026",
"androidId": "5678901234567890123",
"securityToken": "0123456789012345678",
"versionInfo": "Y9B3d2P5mMMSQKri541rkWUVCal3tBg"
}
2 changes: 1 addition & 1 deletion tests/fixtures/credentials.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 4c51098

Please sign in to comment.