firebase-admin 7.4.0__tar.gz → 7.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/PKG-INFO +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/__about__.py +1 -1
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_messaging_encoder.py +45 -12
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_messaging_utils.py +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/app_check.py +53 -9
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/messaging.py +38 -25
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/ml.py +140 -4
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin.egg-info/PKG-INFO +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin.egg-info/requires.txt +3 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/setup.py +1 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_app_check.py +136 -5
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_messaging.py +150 -5
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_ml.py +87 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/testutils.py +4 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/LICENSE +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/README.md +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/__init__.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_auth_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_auth_providers.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_auth_utils.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_http_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_retry.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_rfc3339.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_sseclient.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_token_gen.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_user_identifier.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_user_import.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_user_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/_utils.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/auth.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/credentials.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/db.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/exceptions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/firestore.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/firestore_async.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/functions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/instance_id.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/phone_number_verification.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/project_management.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/remote_config.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/storage.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin/tenant_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin.egg-info/SOURCES.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin.egg-info/dependency_links.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/firebase_admin.egg-info/top_level.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/setup.cfg +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_app.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_auth_providers.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_credentials.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_db.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_exceptions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_firestore.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_firestore_async.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_functions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_http_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_instance_id.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_phone_number_verification.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_project_management.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_remote_config.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_retry.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_rfc3339.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_sseclient.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_storage.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_tenant_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_token_gen.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.6.0}/tests/test_user_mgt.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: firebase_admin
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.6.0
|
|
4
4
|
Summary: Firebase Admin Python SDK
|
|
5
5
|
Home-page: https://firebase.google.com/docs/admin/setup/
|
|
6
6
|
Author: Firebase
|
|
@@ -25,6 +25,7 @@ Requires-Dist: google-api-core[grpc]<3.0.0dev,>=2.25.1; platform_python_implemen
|
|
|
25
25
|
Requires-Dist: google-cloud-firestore>=2.21.0; platform_python_implementation != "PyPy"
|
|
26
26
|
Requires-Dist: google-cloud-storage>=3.1.1
|
|
27
27
|
Requires-Dist: pyjwt[crypto]>=2.10.1
|
|
28
|
+
Requires-Dist: cryptography<44.0.0; platform_python_implementation == "PyPy" and python_version < "3.11"
|
|
28
29
|
Requires-Dist: httpx[http2]==0.28.1
|
|
29
30
|
Dynamic: author
|
|
30
31
|
Dynamic: classifier
|
|
@@ -19,6 +19,7 @@ import json
|
|
|
19
19
|
import math
|
|
20
20
|
import numbers
|
|
21
21
|
import re
|
|
22
|
+
import warnings
|
|
22
23
|
|
|
23
24
|
from firebase_admin import _messaging_utils
|
|
24
25
|
|
|
@@ -27,7 +28,7 @@ class Message:
|
|
|
27
28
|
"""A message that can be sent via Firebase Cloud Messaging.
|
|
28
29
|
|
|
29
30
|
Contains payload information as well as recipient information. In particular, the message must
|
|
30
|
-
contain exactly one of token, topic or condition fields.
|
|
31
|
+
contain exactly one of fid, token, topic or condition fields.
|
|
31
32
|
|
|
32
33
|
Args:
|
|
33
34
|
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
|
|
@@ -37,20 +38,29 @@ class Message:
|
|
|
37
38
|
webpush: An instance of ``messaging.WebpushConfig`` (optional).
|
|
38
39
|
apns: An instance of ``messaging.ApnsConfig`` (optional).
|
|
39
40
|
fcm_options: An instance of ``messaging.FCMOptions`` (optional).
|
|
40
|
-
|
|
41
|
+
fid: The Firebase installation ID of an FCM registered app instance to which the
|
|
42
|
+
message should be sent (optional).
|
|
43
|
+
token: Deprecated. Use ``fid`` instead.
|
|
41
44
|
topic: Name of the FCM topic to which the message should be sent (optional). Topic name
|
|
42
45
|
may contain the ``/topics/`` prefix.
|
|
43
46
|
condition: The FCM condition to which the message should be sent (optional).
|
|
44
47
|
"""
|
|
45
48
|
|
|
46
49
|
def __init__(self, data=None, notification=None, android=None, webpush=None, apns=None,
|
|
47
|
-
fcm_options=None, token=None, topic=None, condition=None):
|
|
50
|
+
fcm_options=None, token=None, topic=None, condition=None, fid=None):
|
|
51
|
+
if token is not None:
|
|
52
|
+
warnings.warn(
|
|
53
|
+
"Message.token is deprecated. Use Message.fid instead.",
|
|
54
|
+
DeprecationWarning,
|
|
55
|
+
stacklevel=2
|
|
56
|
+
)
|
|
48
57
|
self.data = data
|
|
49
58
|
self.notification = notification
|
|
50
59
|
self.android = android
|
|
51
60
|
self.webpush = webpush
|
|
52
61
|
self.apns = apns
|
|
53
62
|
self.fcm_options = fcm_options
|
|
63
|
+
self.fid = fid
|
|
54
64
|
self.token = token
|
|
55
65
|
self.topic = topic
|
|
56
66
|
self.condition = condition
|
|
@@ -60,10 +70,10 @@ class Message:
|
|
|
60
70
|
|
|
61
71
|
|
|
62
72
|
class MulticastMessage:
|
|
63
|
-
"""A message that can be sent to multiple tokens via Firebase Cloud Messaging.
|
|
73
|
+
"""A message that can be sent to multiple tokens or fids via Firebase Cloud Messaging.
|
|
64
74
|
|
|
65
75
|
Args:
|
|
66
|
-
tokens:
|
|
76
|
+
tokens: Deprecated. Use ``fids`` instead (optional).
|
|
67
77
|
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
|
|
68
78
|
strings.
|
|
69
79
|
notification: An instance of ``messaging.Notification`` (optional).
|
|
@@ -71,13 +81,35 @@ class MulticastMessage:
|
|
|
71
81
|
webpush: An instance of ``messaging.WebpushConfig`` (optional).
|
|
72
82
|
apns: An instance of ``messaging.ApnsConfig`` (optional).
|
|
73
83
|
fcm_options: An instance of ``messaging.FCMOptions`` (optional).
|
|
84
|
+
fids: A list of Firebase Installation IDs of targeted app instances (optional).
|
|
74
85
|
"""
|
|
75
|
-
def __init__(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if
|
|
79
|
-
|
|
86
|
+
def __init__(
|
|
87
|
+
self, tokens=None, data=None, notification=None, android=None,
|
|
88
|
+
webpush=None, apns=None, fcm_options=None, fids=None):
|
|
89
|
+
if tokens is not None:
|
|
90
|
+
warnings.warn(
|
|
91
|
+
"MulticastMessage.tokens is deprecated. Use MulticastMessage.fids instead.",
|
|
92
|
+
DeprecationWarning,
|
|
93
|
+
stacklevel=2
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if tokens is None and fids is None:
|
|
97
|
+
raise ValueError(
|
|
98
|
+
"Must specify at least one of MulticastMessage.tokens or MulticastMessage.fids.")
|
|
99
|
+
|
|
100
|
+
if tokens is not None:
|
|
101
|
+
_Validators.check_string_list('MulticastMessage.tokens', tokens)
|
|
102
|
+
if fids is not None:
|
|
103
|
+
_Validators.check_string_list('MulticastMessage.fids', fids)
|
|
104
|
+
|
|
105
|
+
tokens_len = len(tokens) if tokens is not None else 0
|
|
106
|
+
fids_len = len(fids) if fids is not None else 0
|
|
107
|
+
if tokens_len + fids_len > 500:
|
|
108
|
+
raise ValueError(
|
|
109
|
+
'Total number of tokens and fids must not exceed 500.')
|
|
110
|
+
|
|
80
111
|
self.tokens = tokens
|
|
112
|
+
self.fids = fids
|
|
81
113
|
self.data = data
|
|
82
114
|
self.notification = notification
|
|
83
115
|
self.android = android
|
|
@@ -695,6 +727,7 @@ class MessageEncoder(json.JSONEncoder):
|
|
|
695
727
|
'Message.condition', o.condition, non_empty=True),
|
|
696
728
|
'data': _Validators.check_string_dict('Message.data', o.data),
|
|
697
729
|
'notification': MessageEncoder.encode_notification(o.notification),
|
|
730
|
+
'fid': _Validators.check_string('Message.fid', o.fid, non_empty=True),
|
|
698
731
|
'token': _Validators.check_string('Message.token', o.token, non_empty=True),
|
|
699
732
|
'topic': _Validators.check_string('Message.topic', o.topic, non_empty=True),
|
|
700
733
|
'webpush': MessageEncoder.encode_webpush(o.webpush),
|
|
@@ -702,9 +735,9 @@ class MessageEncoder(json.JSONEncoder):
|
|
|
702
735
|
}
|
|
703
736
|
result['topic'] = MessageEncoder.sanitize_topic_name(result.get('topic'))
|
|
704
737
|
result = MessageEncoder.remove_null_values(result)
|
|
705
|
-
target_count = sum(t in result for t in ['token', 'topic', 'condition'])
|
|
738
|
+
target_count = sum(t in result for t in ['fid', 'token', 'topic', 'condition'])
|
|
706
739
|
if target_count != 1:
|
|
707
|
-
raise ValueError('Exactly one of token, topic or condition must be specified.')
|
|
740
|
+
raise ValueError('Exactly one of fid, token, topic or condition must be specified.')
|
|
708
741
|
return result
|
|
709
742
|
|
|
710
743
|
@classmethod
|
|
@@ -519,7 +519,8 @@ class SenderIdMismatchError(exceptions.PermissionDeniedError):
|
|
|
519
519
|
class UnregisteredError(exceptions.NotFoundError):
|
|
520
520
|
"""App instance was unregistered from FCM.
|
|
521
521
|
|
|
522
|
-
This usually means that the token
|
|
522
|
+
This usually means that the registration token or installation ID (FID) used
|
|
523
|
+
is no longer valid and a new one must be used."""
|
|
523
524
|
|
|
524
525
|
def __init__(self, message, cause=None, http_response=None):
|
|
525
526
|
exceptions.NotFoundError.__init__(self, message, cause, http_response)
|
|
@@ -15,38 +15,47 @@
|
|
|
15
15
|
"""Firebase App Check module."""
|
|
16
16
|
|
|
17
17
|
from typing import Any, Dict
|
|
18
|
+
import requests
|
|
18
19
|
import jwt
|
|
19
20
|
from jwt import PyJWKClient, ExpiredSignatureError, InvalidTokenError, DecodeError
|
|
20
21
|
from jwt import InvalidAudienceError, InvalidIssuerError, InvalidSignatureError
|
|
21
|
-
from firebase_admin import _utils
|
|
22
|
+
from firebase_admin import _http_client, _utils, exceptions
|
|
22
23
|
|
|
23
24
|
_APP_CHECK_ATTRIBUTE = '_app_check'
|
|
24
25
|
|
|
25
26
|
def _get_app_check_service(app) -> Any:
|
|
26
27
|
return _utils.get_app_service(app, _APP_CHECK_ATTRIBUTE, _AppCheckService)
|
|
27
28
|
|
|
28
|
-
def verify_token(token: str, app=None) -> Dict[str, Any]:
|
|
29
|
-
"""Verifies a Firebase App Check token.
|
|
29
|
+
def verify_token(token: str, app=None, consume: bool = False) -> Dict[str, Any]:
|
|
30
|
+
"""Verifies a Firebase App Check token, optionally consuming limited-use tokens.
|
|
30
31
|
|
|
31
32
|
Args:
|
|
32
33
|
token: A token from App Check.
|
|
33
34
|
app: An App instance (optional).
|
|
35
|
+
consume: Set to ``True`` only if the token is a limited-use (one-time) token
|
|
36
|
+
that should be consumed upon verification (optional, defaults to ``False``).
|
|
34
37
|
|
|
35
38
|
Returns:
|
|
36
|
-
Dict[str, Any]: The token's decoded claims.
|
|
39
|
+
Dict[str, Any]: The token's decoded claims. If ``consume`` is ``True``, the dictionary
|
|
40
|
+
also includes an ``already_consumed`` boolean key indicating whether the token was
|
|
41
|
+
previously consumed.
|
|
37
42
|
|
|
38
43
|
Raises:
|
|
39
|
-
ValueError: If the app's ``project_id``
|
|
40
|
-
|
|
44
|
+
ValueError: If ``consume`` is not a boolean, or if the app's ``project_id``
|
|
45
|
+
is invalid or unspecified, or if the token's headers or payload are invalid.
|
|
46
|
+
FirebaseError: If an error occurs while communicating with the App Check service.
|
|
41
47
|
PyJWKClientError: If PyJWKClient fails to fetch a valid signing key.
|
|
42
48
|
"""
|
|
43
|
-
return _get_app_check_service(app).verify_token(token)
|
|
49
|
+
return _get_app_check_service(app).verify_token(token, consume=consume)
|
|
44
50
|
|
|
45
51
|
class _AppCheckService:
|
|
46
52
|
"""Service class that implements Firebase App Check functionality."""
|
|
47
53
|
|
|
48
54
|
_APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/'
|
|
49
55
|
_JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1/jwks'
|
|
56
|
+
_VERIFY_URL_FORMAT = (
|
|
57
|
+
'https://firebaseappcheck.googleapis.com/v1/projects/{project_id}:verifyAppCheckToken'
|
|
58
|
+
)
|
|
50
59
|
_project_id = None
|
|
51
60
|
_scoped_project_id = None
|
|
52
61
|
_jwks_client = None
|
|
@@ -68,11 +77,15 @@ class _AppCheckService:
|
|
|
68
77
|
# Default lifespan is 300 seconds (5 minutes) so we change it to 21600 seconds (6 hours).
|
|
69
78
|
self._jwks_client = PyJWKClient(
|
|
70
79
|
self._JWKS_URL, lifespan=21600, headers=self._APP_CHECK_HEADERS)
|
|
80
|
+
timeout = app.options.get('httpTimeout', _http_client.DEFAULT_TIMEOUT_SECONDS)
|
|
81
|
+
self._http_client = _http_client.JsonHttpClient(
|
|
82
|
+
credential=app.credential.get_credential(), timeout=timeout)
|
|
71
83
|
|
|
72
84
|
|
|
73
|
-
def verify_token(self, token: str) -> Dict[str, Any]:
|
|
74
|
-
"""Verifies a Firebase App Check token."""
|
|
85
|
+
def verify_token(self, token: str, consume: bool = False) -> Dict[str, Any]:
|
|
86
|
+
"""Verifies a Firebase App Check token, optionally consuming limited-use tokens."""
|
|
75
87
|
_Validators.check_string("app check token", token)
|
|
88
|
+
_Validators.check_boolean("consume", consume)
|
|
76
89
|
|
|
77
90
|
# Obtain the Firebase App Check Public Keys
|
|
78
91
|
# Note: It is not recommended to hard code these keys as they rotate,
|
|
@@ -87,8 +100,32 @@ class _AppCheckService:
|
|
|
87
100
|
) from exception
|
|
88
101
|
|
|
89
102
|
verified_claims['app_id'] = verified_claims.get('sub')
|
|
103
|
+
|
|
104
|
+
if consume:
|
|
105
|
+
verified_claims['already_consumed'] = self._verify_replay_protection(token)
|
|
106
|
+
|
|
90
107
|
return verified_claims
|
|
91
108
|
|
|
109
|
+
def _verify_replay_protection(self, token: str) -> bool:
|
|
110
|
+
"""Verifies replay protection with the backend and returns the alreadyConsumed status."""
|
|
111
|
+
url = self._VERIFY_URL_FORMAT.format(project_id=self._project_id)
|
|
112
|
+
try:
|
|
113
|
+
body = self._http_client.body('post', url, json={'app_check_token': token})
|
|
114
|
+
except requests.exceptions.RequestException as error:
|
|
115
|
+
raise _utils.handle_platform_error_from_requests(error)
|
|
116
|
+
except ValueError as error:
|
|
117
|
+
raise exceptions.UnknownError(
|
|
118
|
+
f'Unexpected response from App Check service: {error}'
|
|
119
|
+
) from error
|
|
120
|
+
|
|
121
|
+
if not isinstance(body, dict):
|
|
122
|
+
raise exceptions.UnknownError(
|
|
123
|
+
'Unexpected response from App Check service. '
|
|
124
|
+
f'Expected a JSON object, but got {type(body).__name__}.'
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return bool(body.get('alreadyConsumed', False))
|
|
128
|
+
|
|
92
129
|
def _has_valid_token_headers(self, headers: Any) -> None:
|
|
93
130
|
"""Checks whether the token has valid headers for App Check."""
|
|
94
131
|
# Ensure the token's header has type JWT
|
|
@@ -159,3 +196,10 @@ class _Validators:
|
|
|
159
196
|
raise ValueError(f'{label} "{value}" must be a non-empty string.')
|
|
160
197
|
if not isinstance(value, str):
|
|
161
198
|
raise ValueError(f'{label} "{value}" must be a string.')
|
|
199
|
+
|
|
200
|
+
@classmethod
|
|
201
|
+
def check_boolean(cls, label: str, value: Any):
|
|
202
|
+
"""Checks if the given value is a boolean."""
|
|
203
|
+
if not isinstance(value, bool):
|
|
204
|
+
raise ValueError(f'{label} must be a boolean.')
|
|
205
|
+
return value
|
|
@@ -20,6 +20,7 @@ import concurrent.futures
|
|
|
20
20
|
import json
|
|
21
21
|
import asyncio
|
|
22
22
|
import logging
|
|
23
|
+
import warnings
|
|
23
24
|
import requests
|
|
24
25
|
import httpx
|
|
25
26
|
|
|
@@ -172,13 +173,45 @@ async def send_each_async(
|
|
|
172
173
|
"""
|
|
173
174
|
return await _get_messaging_service(app).send_each_async(messages, dry_run)
|
|
174
175
|
|
|
176
|
+
def _get_messages_from_multicast(multicast_message: MulticastMessage) -> List[Message]:
|
|
177
|
+
"""Extracts individual Message objects from a MulticastMessage."""
|
|
178
|
+
if not isinstance(multicast_message, MulticastMessage):
|
|
179
|
+
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
180
|
+
|
|
181
|
+
messages = []
|
|
182
|
+
if multicast_message.tokens is not None:
|
|
183
|
+
with warnings.catch_warnings():
|
|
184
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
|
185
|
+
messages.extend([Message(
|
|
186
|
+
data=multicast_message.data,
|
|
187
|
+
notification=multicast_message.notification,
|
|
188
|
+
android=multicast_message.android,
|
|
189
|
+
webpush=multicast_message.webpush,
|
|
190
|
+
apns=multicast_message.apns,
|
|
191
|
+
fcm_options=multicast_message.fcm_options,
|
|
192
|
+
token=token
|
|
193
|
+
) for token in multicast_message.tokens])
|
|
194
|
+
|
|
195
|
+
if multicast_message.fids is not None:
|
|
196
|
+
messages.extend([Message(
|
|
197
|
+
data=multicast_message.data,
|
|
198
|
+
notification=multicast_message.notification,
|
|
199
|
+
android=multicast_message.android,
|
|
200
|
+
webpush=multicast_message.webpush,
|
|
201
|
+
apns=multicast_message.apns,
|
|
202
|
+
fcm_options=multicast_message.fcm_options,
|
|
203
|
+
fid=fid
|
|
204
|
+
) for fid in multicast_message.fids])
|
|
205
|
+
|
|
206
|
+
return messages
|
|
207
|
+
|
|
175
208
|
async def send_each_for_multicast_async(
|
|
176
209
|
multicast_message: MulticastMessage,
|
|
177
210
|
dry_run: bool = False,
|
|
178
211
|
app: Optional[App] = None
|
|
179
212
|
) -> BatchResponse:
|
|
180
|
-
"""Sends the given
|
|
181
|
-
(FCM).
|
|
213
|
+
"""Sends the given multicast message to each token or fid asynchronously via
|
|
214
|
+
Firebase Cloud Messaging (FCM).
|
|
182
215
|
|
|
183
216
|
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
|
|
184
217
|
recipients. Instead, FCM performs all the usual validations and emulates the send operation.
|
|
@@ -195,21 +228,11 @@ async def send_each_for_multicast_async(
|
|
|
195
228
|
FirebaseError: If an error occurs while sending the message to the FCM service.
|
|
196
229
|
ValueError: If the input arguments are invalid.
|
|
197
230
|
"""
|
|
198
|
-
|
|
199
|
-
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
200
|
-
messages = [Message(
|
|
201
|
-
data=multicast_message.data,
|
|
202
|
-
notification=multicast_message.notification,
|
|
203
|
-
android=multicast_message.android,
|
|
204
|
-
webpush=multicast_message.webpush,
|
|
205
|
-
apns=multicast_message.apns,
|
|
206
|
-
fcm_options=multicast_message.fcm_options,
|
|
207
|
-
token=token
|
|
208
|
-
) for token in multicast_message.tokens]
|
|
231
|
+
messages = _get_messages_from_multicast(multicast_message)
|
|
209
232
|
return await _get_messaging_service(app).send_each_async(messages, dry_run)
|
|
210
233
|
|
|
211
234
|
def send_each_for_multicast(multicast_message, dry_run=False, app=None):
|
|
212
|
-
"""Sends the given
|
|
235
|
+
"""Sends the given multicast message to each token or fid via Firebase Cloud Messaging (FCM).
|
|
213
236
|
|
|
214
237
|
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
|
|
215
238
|
recipients. Instead, FCM performs all the usual validations and emulates the send operation.
|
|
@@ -226,17 +249,7 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
|
|
|
226
249
|
FirebaseError: If an error occurs while sending the message to the FCM service.
|
|
227
250
|
ValueError: If the input arguments are invalid.
|
|
228
251
|
"""
|
|
229
|
-
|
|
230
|
-
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
231
|
-
messages = [Message(
|
|
232
|
-
data=multicast_message.data,
|
|
233
|
-
notification=multicast_message.notification,
|
|
234
|
-
android=multicast_message.android,
|
|
235
|
-
webpush=multicast_message.webpush,
|
|
236
|
-
apns=multicast_message.apns,
|
|
237
|
-
fcm_options=multicast_message.fcm_options,
|
|
238
|
-
token=token
|
|
239
|
-
) for token in multicast_message.tokens]
|
|
252
|
+
messages = _get_messages_from_multicast(multicast_message)
|
|
240
253
|
return _get_messaging_service(app).send_each(messages, dry_run)
|
|
241
254
|
|
|
242
255
|
def subscribe_to_topic(tokens, topic, app=None):
|