firebase-admin 7.3.0__tar.gz → 7.5.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.3.0 → firebase_admin-7.5.0}/PKG-INFO +2 -1
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/__about__.py +1 -1
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_messaging_encoder.py +45 -12
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_messaging_utils.py +2 -1
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/messaging.py +38 -25
- firebase_admin-7.5.0/firebase_admin/phone_number_verification.py +250 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/PKG-INFO +2 -1
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/SOURCES.txt +2 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/requires.txt +3 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/setup.py +1 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_messaging.py +150 -5
- firebase_admin-7.5.0/tests/test_phone_number_verification.py +311 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/testutils.py +4 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/LICENSE +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/README.md +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/__init__.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_auth_client.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_auth_providers.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_auth_utils.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_http_client.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_retry.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_rfc3339.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_sseclient.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_token_gen.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_user_identifier.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_user_import.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_user_mgt.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/_utils.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/app_check.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/auth.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/credentials.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/db.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/exceptions.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/firestore.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/firestore_async.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/functions.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/instance_id.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/ml.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/project_management.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/remote_config.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/storage.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin/tenant_mgt.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/dependency_links.txt +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/top_level.txt +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/setup.cfg +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_app.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_app_check.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_auth_providers.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_credentials.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_db.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_exceptions.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_firestore.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_firestore_async.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_functions.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_http_client.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_instance_id.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_ml.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_project_management.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_remote_config.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_retry.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_rfc3339.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_sseclient.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_storage.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_tenant_mgt.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.0}/tests/test_token_gen.py +0 -0
- {firebase_admin-7.3.0 → firebase_admin-7.5.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.5.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)
|
|
@@ -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):
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Copyright 2026 Google Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Firebase Phone Number Verification module.
|
|
16
|
+
|
|
17
|
+
This module contains functions for verifying JWTs related to the Firebase
|
|
18
|
+
Phone Number Verification service.
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
from typing import Any, Dict, Optional
|
|
22
|
+
|
|
23
|
+
import jwt
|
|
24
|
+
from jwt import (
|
|
25
|
+
PyJWKClient, InvalidSignatureError,
|
|
26
|
+
PyJWKClientError, InvalidAudienceError, InvalidIssuerError, ExpiredSignatureError
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from firebase_admin import App, _utils, exceptions
|
|
30
|
+
|
|
31
|
+
_FPNV_ATTRIBUTE = '_phone_number_verification'
|
|
32
|
+
_FPNV_JWKS_URL = 'https://fpnv.googleapis.com/v1beta/jwks'
|
|
33
|
+
_FPNV_ISSUER = 'https://fpnv.googleapis.com/projects/'
|
|
34
|
+
_ALGORITHM_ES256 = 'ES256'
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _get_fpnv_service(app):
|
|
38
|
+
return _utils.get_app_service(app, _FPNV_ATTRIBUTE, _FpnvService)
|
|
39
|
+
|
|
40
|
+
def verify_token(token: str, app: Optional[App] = None) -> PhoneNumberVerificationToken:
|
|
41
|
+
"""Verifies a Firebase Phone Number Verification token.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
token: A string containing the Firebase Phone Number Verification JWT.
|
|
45
|
+
app: An App instance (optional).
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
PhoneNumberVerificationToken: The verified token claims.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: If the token is not a string or is empty.
|
|
52
|
+
InvalidTokenError: If the token is invalid or malformed.
|
|
53
|
+
ExpiredTokenError: If the token has expired.
|
|
54
|
+
"""
|
|
55
|
+
return _get_fpnv_service(app).verify_token(token)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class PhoneNumberVerificationToken(dict):
|
|
59
|
+
"""Represents a verified Firebase Phone Number Verification token.
|
|
60
|
+
|
|
61
|
+
This class behaves like a dictionary, allowing access to the decoded claims.
|
|
62
|
+
It also provides convenience properties for common claims.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def __init__(self, claims):
|
|
66
|
+
super().__init__(claims)
|
|
67
|
+
self['phone_number'] = claims.get('sub')
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def phone_number(self) -> str:
|
|
71
|
+
"""Returns the phone number of the user.
|
|
72
|
+
This corresponds to the 'sub' claim in the JWT.
|
|
73
|
+
"""
|
|
74
|
+
return self.get('sub')
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def issuer(self) -> str:
|
|
78
|
+
"""Returns the issuer identifier for the issuer of the response."""
|
|
79
|
+
return self.get('iss')
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def audience(self) -> str:
|
|
83
|
+
"""Returns the audience for which this token is intended."""
|
|
84
|
+
return self.get('aud')
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def exp(self) -> int:
|
|
88
|
+
"""Returns the expiration time since the Unix epoch."""
|
|
89
|
+
return self.get('exp')
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def iat(self) -> int:
|
|
93
|
+
"""Returns the issued-at time since the Unix epoch."""
|
|
94
|
+
return self.get('iat')
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def sub(self) -> str:
|
|
98
|
+
"""Returns the sub (subject) of the token, which is the phone number."""
|
|
99
|
+
return self.get('sub')
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def claims(self):
|
|
103
|
+
"""Returns the entire map of claims."""
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class _FpnvService:
|
|
108
|
+
"""Service class that implements Firebase Phone Number Verification functionality."""
|
|
109
|
+
_project_id = None
|
|
110
|
+
|
|
111
|
+
def __init__(self, app):
|
|
112
|
+
self._project_id = app.project_id
|
|
113
|
+
if not self._project_id:
|
|
114
|
+
raise ValueError(
|
|
115
|
+
'Project ID is required for Firebase Phone Number Verification. Please ensure the '
|
|
116
|
+
'app is initialized with a credential that contains a project ID.'
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
self._verifier = _FpnvTokenVerifier(self._project_id)
|
|
120
|
+
|
|
121
|
+
def verify_token(self, token) -> PhoneNumberVerificationToken:
|
|
122
|
+
"""Verifies a Firebase Phone Number Verification token.
|
|
123
|
+
|
|
124
|
+
Verifies the signature, expiration, and claims of the token.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
token: A string containing the Firebase Phone Number Verification JWT.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
PhoneNumberVerificationToken: The verified token claims.
|
|
131
|
+
|
|
132
|
+
Raises:
|
|
133
|
+
ValueError: If the token is not a string or is empty.
|
|
134
|
+
InvalidTokenError: If the token is invalid or malformed.
|
|
135
|
+
ExpiredTokenError: If the token has expired.
|
|
136
|
+
"""
|
|
137
|
+
return PhoneNumberVerificationToken(self._verifier.verify(token))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class _FpnvTokenVerifier:
|
|
141
|
+
"""Internal class for verifying Firebase Phone Number Verification JWTs signed with ES256."""
|
|
142
|
+
_jwks_client = None
|
|
143
|
+
_project_id = None
|
|
144
|
+
|
|
145
|
+
def __init__(self, project_id):
|
|
146
|
+
self._project_id = project_id
|
|
147
|
+
self._jwks_client = PyJWKClient(_FPNV_JWKS_URL, lifespan=21600)
|
|
148
|
+
|
|
149
|
+
def verify(self, token) -> Dict[str, Any]:
|
|
150
|
+
"""Verifies the given Firebase Phone Number Verification token."""
|
|
151
|
+
_Validators.check_string("Firebase Phone Number Verification check token", token)
|
|
152
|
+
try:
|
|
153
|
+
self._validate_headers(jwt.get_unverified_header(token))
|
|
154
|
+
signing_key = self._jwks_client.get_signing_key_from_jwt(token)
|
|
155
|
+
claims = self._decode_and_verify(token, signing_key.key)
|
|
156
|
+
except (jwt.InvalidTokenError, PyJWKClientError) as exception:
|
|
157
|
+
raise InvalidTokenError(
|
|
158
|
+
'Verifying phone number verification token failed.',
|
|
159
|
+
cause=exception,
|
|
160
|
+
http_response=getattr(exception, 'http_response', None)
|
|
161
|
+
) from exception
|
|
162
|
+
|
|
163
|
+
return claims
|
|
164
|
+
|
|
165
|
+
def _validate_headers(self, headers: Any) -> None:
|
|
166
|
+
"""Validates the headers."""
|
|
167
|
+
if headers.get('kid') is None:
|
|
168
|
+
raise InvalidTokenError("Token has no 'kid' claim.")
|
|
169
|
+
|
|
170
|
+
if headers.get('typ') != 'JWT':
|
|
171
|
+
raise InvalidTokenError(
|
|
172
|
+
'The provided token has an incorrect type header. ' \
|
|
173
|
+
f"Expected 'JWT' but got {headers.get('typ')!r}."
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
algorithm = headers.get('alg')
|
|
177
|
+
if algorithm != _ALGORITHM_ES256:
|
|
178
|
+
raise InvalidTokenError(
|
|
179
|
+
'The provided token has an incorrect alg header. '
|
|
180
|
+
f'Expected {_ALGORITHM_ES256} but got {algorithm}.'
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
def _decode_and_verify(self, token, signing_key) -> Dict[str, Any]:
|
|
184
|
+
"""Decodes and verifies the token."""
|
|
185
|
+
expected_issuer = f'{_FPNV_ISSUER}{self._project_id}'
|
|
186
|
+
try:
|
|
187
|
+
payload = jwt.decode(
|
|
188
|
+
token,
|
|
189
|
+
signing_key,
|
|
190
|
+
algorithms=[_ALGORITHM_ES256],
|
|
191
|
+
audience=expected_issuer,
|
|
192
|
+
issuer=expected_issuer
|
|
193
|
+
)
|
|
194
|
+
except InvalidSignatureError as exception:
|
|
195
|
+
raise InvalidTokenError(
|
|
196
|
+
'The provided token has an invalid signature.'
|
|
197
|
+
) from exception
|
|
198
|
+
except InvalidAudienceError as exception:
|
|
199
|
+
raise InvalidTokenError(
|
|
200
|
+
'The provided token has an incorrect "aud" (audience) claim. '
|
|
201
|
+
f'Expected {expected_issuer}.'
|
|
202
|
+
) from exception
|
|
203
|
+
except InvalidIssuerError as exception:
|
|
204
|
+
raise InvalidTokenError(
|
|
205
|
+
'The provided token has an incorrect "iss" (issuer) claim. '
|
|
206
|
+
f'Expected {expected_issuer}.'
|
|
207
|
+
) from exception
|
|
208
|
+
except ExpiredSignatureError as exception:
|
|
209
|
+
raise ExpiredTokenError(
|
|
210
|
+
'The provided token has expired.'
|
|
211
|
+
) from exception
|
|
212
|
+
except jwt.InvalidTokenError as exception:
|
|
213
|
+
raise InvalidTokenError(
|
|
214
|
+
f'Decoding token failed. Error: {exception}'
|
|
215
|
+
) from exception
|
|
216
|
+
|
|
217
|
+
sub_claim = payload.get('sub')
|
|
218
|
+
if not isinstance(sub_claim, str) or not sub_claim:
|
|
219
|
+
raise InvalidTokenError(
|
|
220
|
+
'The provided token has an incorrect "sub" (subject) claim. '
|
|
221
|
+
'Expected a non-empty string.'
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
return payload
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
class _Validators:
|
|
228
|
+
"""A collection of data validation utilities.
|
|
229
|
+
|
|
230
|
+
Methods provided in this class raise ``ValueErrors`` if any validations fail.
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
@classmethod
|
|
234
|
+
def check_string(cls, label: str, value: Any):
|
|
235
|
+
"""Checks if the given value is a string."""
|
|
236
|
+
if not isinstance(value, str) or not value:
|
|
237
|
+
raise ValueError(f'{label} must be a non-empty string.')
|
|
238
|
+
|
|
239
|
+
# Firebase Phone Number Verification Errors
|
|
240
|
+
class InvalidTokenError(exceptions.InvalidArgumentError):
|
|
241
|
+
"""Raised when a Firebase Phone Number Verification token is invalid."""
|
|
242
|
+
|
|
243
|
+
def __init__(self, message, cause=None, http_response=None):
|
|
244
|
+
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)
|
|
245
|
+
|
|
246
|
+
class ExpiredTokenError(InvalidTokenError):
|
|
247
|
+
"""Raised when a Firebase Phone Number Verification token is expired."""
|
|
248
|
+
|
|
249
|
+
def __init__(self, message, cause=None, http_response=None):
|
|
250
|
+
InvalidTokenError.__init__(self, message, cause, http_response)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: firebase_admin
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.5.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
|
|
@@ -29,6 +29,7 @@ firebase_admin/functions.py
|
|
|
29
29
|
firebase_admin/instance_id.py
|
|
30
30
|
firebase_admin/messaging.py
|
|
31
31
|
firebase_admin/ml.py
|
|
32
|
+
firebase_admin/phone_number_verification.py
|
|
32
33
|
firebase_admin/project_management.py
|
|
33
34
|
firebase_admin/remote_config.py
|
|
34
35
|
firebase_admin/storage.py
|
|
@@ -51,6 +52,7 @@ tests/test_http_client.py
|
|
|
51
52
|
tests/test_instance_id.py
|
|
52
53
|
tests/test_messaging.py
|
|
53
54
|
tests/test_ml.py
|
|
55
|
+
tests/test_phone_number_verification.py
|
|
54
56
|
tests/test_project_management.py
|
|
55
57
|
tests/test_remote_config.py
|
|
56
58
|
tests/test_retry.py
|
|
@@ -42,6 +42,7 @@ install_requires = [
|
|
|
42
42
|
'google-cloud-firestore>=2.21.0; platform.python_implementation != "PyPy"',
|
|
43
43
|
'google-cloud-storage>=3.1.1',
|
|
44
44
|
'pyjwt[crypto] >= 2.10.1',
|
|
45
|
+
'cryptography < 44.0.0; platform.python_implementation == "PyPy" and python_version < "3.11"',
|
|
45
46
|
'httpx[http2] == 0.28.1',
|
|
46
47
|
]
|
|
47
48
|
|