8000 Merged with master · alihen/firebase-admin-python@9b367ec · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b367ec

Browse files
committed
Merged with master
2 parents 2e20cd0 + f2dd24e commit 9b367ec

File tree

13 files changed

+803
-38
lin 10000 es changed

13 files changed

+803
-38
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
-
44

5+
# v2.17.0
6+
7+
- [added] Added new `send_all()` and `send_multicast()` APIs to the
8+
`messasing` module.
9+
- [added] Added a new `auth.DELETE_ATTRIBUTE` sentinel value, which can be
10+
used to delete `phone_number`, `display_name`, `photo_url` and `custom_claims`
11+
attributes from a user account. It is now recommended to use this sentinel
12+
value over passing `None` for deleting attributes.
13+
514
# v2.16.0
615

716
- [added] Added `generate_password_reset_link()`,

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ $ pip install -r requirements.txt # Install additional tools and dependencies
106106

107107
We use [pylint](https://pylint.org/) for verifying source code format, and
108108
enforcing other Python programming best practices.
109-
There is a pylint configuration file ([`.pylintrc`](../.pylintrc)) at the root of this Git
109+
There is a pylint configuration file ([`.pylintrc`](.pylintrc)) at the root of this Git
110110
repository. This enables you to invoke pylint directly from the command line:
111111

112112
```
113113
pylint firebase_admin
114114
```
115115

116-
However, it is recommended that you use the [`lint.sh`](../lint.sh) bash script to invoke
116+
However, it is recommended that you use the [`lint.sh`](lint.sh) bash script to invoke
117117
pylint. This script will run the linter on both `firebase_admin` and the corresponding
118118
`tests` module. It suprresses some of the noisy warnings that get generated
119119
when running pylint on test code. Note that by default `lint.sh` will only
@@ -226,7 +226,7 @@ pyenv install 3.3.0 # install Python 3.3.0
226226
pyenv install pypy2-5.6.0 # install pypy2
227227
```
228228

229-
Refer to the [`tox.ini`](../tox.ini) file for a list of target environments that we usually test.
229+
Refer to the [`tox.ini`](tox.ini) file for a list of target environments that we usually test.
230230
Use pyenv to install all the required Python versions on your workstation. Verify that they are
231231
installed by running the following command:
232232

firebase_admin/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""About information (version, etc) for Firebase Admin SDK."""
1616

17-
__version__ = '2.16.0'
17+
__version__ = '2.17.0'
1818
__title__ = 'firebase_admin'
1919
__author__ = 'Firebase'
2020
__license__ = 'Apache License 2.0'

firebase_admin/_messaging_utils.py

Lines changed: 25 additions & 1 deletion
57
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ def __init__(self, data=None, notification=None, android=None, webpush=None, apn
5454
self.condition = condition
5555

5656

+
class MulticastMessage(object):
58+
"""A message that can be sent to multiple tokens via Firebase Cloud Messaging.
59+
60+
Args:
61+
tokens: A list of registration tokens of targeted devices.
62+
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
63+
strings.
64+
notification: An instance of ``messaging.Notification`` (optional).
65+
android: An instance of ``messaging.AndroidConfig`` (optional).
66+
webpush: An instance of ``messaging.WebpushConfig`` (optional).
67+
apns: An instance of ``messaging.ApnsConfig`` (optional).
68+
"""
69+
def __init__(self, tokens, data=None, notification=None, android=None, webpush=None, apns=None):
70+
_Validators.check_string_list('MulticastMessage.tokens', tokens)
71+
if len(tokens) > 100:
72+
raise ValueError('MulticastMessage.tokens must not contain more than 100 tokens.')
73+
self.tokens = tokens
74+
self.data = data
75+
self.notification = notification
76+
self.android = android
77+
self.webpush = webpush
78+
self.apns = apns
79+
80+
5781
class Notification(object):
5882
"""A notification that can be included in a message.
5983
@@ -150,7 +174,7 @@ class WebpushConfig(object):
150174
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
151175
strings. When specified, overrides any data fields set via ``Message.data``.
152176
notification: A ``messag F438 ing.WebpushNotification`` to be included in the message (optional).
153-
fcm_options: A ``messaging.WebpushFcmOptions`` instance to be included in the messsage
177+
fcm_options: A ``messaging.WebpushFcmOptions`` instance to be included in the message
154178
(optional).
155179
156180
.. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5

firebase_admin/_user_mgt.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@
3030
MAX_LIST_USERS_RESULTS = 1000
3131
MAX_IMPORT_USERS_SIZE = 1000
3232

33-
class _Unspecified(object):
34-
pass
33+
34+
class Sentinel(object):
35+
36+
def __init__(self, description):
37+
self.description = description
38+
3539

3640
# Use this internally, until sentinels are available in the public API.
37-
_UNSPECIFIED = _Unspecified()
41+
_UNSPECIFIED = Sentinel('No value specified')
42+
43+
44+
DELETE_ATTRIBUTE = Sentinel('Value used to delete an attribute from a user profile')
3845

3946

4047
class UserMetadata(object):
@@ -541,26 +548,26 @@ def update_user(self, uid, display_name=_UNSPECIFIED, email=None, phone_number=_
541548

542549
remove = []
543550
if display_name is not _UNSPECIFIED:
544-
if display_name is None:
551+
if display_name is None or display_name is DELETE_ATTRIBUTE:
545552
remove.append('DISPLAY_NAME')
546553
else:
547554
payload['displayName'] = _auth_utils.validate_display_name(display_name)
548555
if photo_url is not _UNSPECIFIED:
549-
if photo_url is None:
556+
if photo_url is None or photo_url is DELETE_ATTRIBUTE:
550557
remove.append('PHOTO_URL')
551558
else:
552559
payload['photoUrl'] = _auth_utils.validate_photo_url(photo_url)
553560
if remove:
554561
payload['deleteAttribute'] = remove
555562

556563
if phone_number is not _UNSPECIFIED:
557-
if phone_number is None:
564+
if phone_number is None or phone_number is DELETE_ATTRIBUTE:
558565
payload['deleteProvider'] = ['phone']
559566
else:
560567
payload['phoneNumber'] = _auth_utils.validate_phone(phone_number)
561568

562569
if custom_claims is not _UNSPECIFIED:
563-
if custom_claims is None:
570+
if custom_claims is None or custom_claims is DELETE_ATTRIBUTE:
564571
custom_claims = {}
565572
json_claims = json.dumps(custom_claims) if isinstance(
566573
custom_claims, dict) else custom_claims

firebase_admin/auth.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
__all__ = [
3838
'ActionCodeSettings',
39+
'AuthError',
40+
'DELETE_ATTRIBUTE',
3941
'ErrorInfo',
4042
'ExportedUserRecord',
4143
'FirebaseAuthError',
@@ -80,6 +82,7 @@
8082

8183

8284
ActionCodeSettings = _user_mgt.ActionCodeSettings
85+
DELETE_ATTRIBUTE = _user_mgt.DELETE_ATTRIBUTE
8386
ErrorInfo = _user_import.ErrorInfo
8487
ExportedUserRecord = _user_mgt.ExportedUserRecord
8588
FirebaseAuthError = _auth_utils.FirebaseAuthError
@@ -145,6 +148,7 @@ def create_custom_token(uid, developer_claims=None, app=None):
145148
return token_generator.create_custom_token(uid, developer_claims)
146149

147150

151+
148152
def verify_id_token(id_token, app=None, check_revoked=False):
149153
"""Verifies the signature and data for the provided JWT.
150154
@@ -197,6 +201,7 @@ def create_session_cookie(id_token, expires_in, app=None):
197201
return token_generator.create_session_cookie(id_token, expires_in)
198202

199203

204+
200205
def verify_session_cookie(session_cookie, check_revoked=False, app=None):
201206
"""Verifies a Firebase session cookie.
202207
@@ -262,6 +267,7 @@ def get_user(uid, app=None):
262267
return UserRecord(response)
263268

264269

270+
265271
def get_user_by_email(email, app=None):
266272
"""Gets the user data corresponding to the specified user email.
267273
@@ -302,6 +308,7 @@ def get_user_by_phone_number(phone_number, app=None):
302308
return UserRecord(response)
303309

304310

311+
305312
def list_users(page_token=None, max_results=_user_mgt.MAX_LIST_USERS_RESULTS, app=None):
306313
"""Retrieves a page of user accounts from a Firebase project.
307314
@@ -367,17 +374,18 @@ def update_user(uid, **kwargs):
367374
368375
Keyword Args:
369376
display_name: The user's display name (optional). Can be removed by explicitly passing
370-
None.
377+
``auth.DELETE_ATTRIBUTE``.
371378
email: The user's primary email (optional).
372379
email_verified: A boolean indicating whether or not the user's primary email is
373380
verified (optional).
374381
phone_number: The user's primary phone number (optional). Can be removed by explicitly
375-
passing None.
376-
photo_url: The user's photo URL (optional). Can be removed by explicitly passing None.
382+
passing ``auth.DELETE_ATTRIBUTE``.
383+
photo_url: The user's photo URL (optional). Can be removed by explicitly passing
384+
``auth.DELETE_ATTRIBUTE``.
377385
password: The user's raw, unhashed password. (optional).
378386
disabled: A boolean indicating whether or not the user account is disabled (optional).
379387
custom_claims: A dictionary or a JSON string contining the custom claims to be set on the
380-
user account (optional).
388+
user account (optional). To remove all custom claims, pass ``auth.DELETE_ATTRIBUTE``.
381389
valid_since: An integer signifying the seconds since the epoch. This field is set by
382390
``revoke_refresh_tokens`` and it is discouraged to set this field directly.
383391
@@ -394,6 +402,7 @@ def update_user(uid, **kwargs):
394402
return UserRecord(user_manager.get_user(uid=uid))
395403

396404

405+
397406
def set_custom_user_claims(uid, custom_claims, app=None):
398407
"""Sets additional claims on an existing user account.
399408
@@ -418,6 +427,7 @@ def set_custom_user_claims(uid, custom_claims, app=None):
418427
user_manager.update_user(uid, custom_claims=custom_claims)
419428

420429

430+
421431
def delete_user(uid, app=None):
422432
"""Deletes the user identified by the specified user ID.
423433
@@ -433,6 +443,7 @@ def delete_user(uid, app=None):
433443
user_manager.delete_user(uid)
434444

435445

446+
436447
def import_users(users, hash_alg=None, app=None):
437448
"""Imports the specified list of users into Firebase Auth.
438449
@@ -460,6 +471,7 @@ def import_users(users, hash_alg=None, app=None):
460471
return UserImportResult(result, len(users))
461472

462473

474+
463475
def generate_password_reset_link(email, action_code_settings=None, app=None):
464476
"""Generates the out-of-band email action link for password reset flows for the specified email
465477
address.
@@ -482,6 +494,7 @@ def generate_password_reset_link(email, action_code_settings=None, app=None):
482494
'PASSWORD_RESET', email, action_code_settings=action_code_settings)
483495

484496

497+
485498
def generate_email_verification_link(email, action_code_settings=None, app=None):
486499
"""Generates the out-of-band email action link for email verification flows for the specified
487500
email address.
@@ -504,6 +517,7 @@ def generate_email_verification_link(email, action_code_settings=None, app=None)
504517
'VERIFY_EMAIL', email, action_code_settings=action_code_settings)
505518

506519

520+
507521
def generate_sign_in_with_email_link(email, action_code_settings, app=None):
508522
"""Generates the out-of-band email action link for email link sign-in flows, using the action
509523
code settings provided.
@@ -526,6 +540,7 @@ def generate_sign_in_with_email_link(email, action_code_settings, app=None):
526540
'EMAIL_SIGNIN', email, action_code_settings=action_code_settings)
527541

528542

543+
529544
def _check_jwt_revoked(verified_claims, error_code, label, app):
530545
user = get_user(verified_claims.get('uid'), app=app)
531546
if verified_claims.get('iat') * 1000 < user.tokens_valid_after_timestamp:

firebase_admin/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def listen(self, callback):
351351
352352
The specified callback function will get invoked with ``db.Event`` objects for each
353353
realtime update received from the database. It will also get called whenever the SDK
354-
reconnects to the server due to network issues and credential expiration. In general,
354+
reconnects to the server due to network issues or credential expiration. In general,
355355
the OAuth2 credentials used to authorize connections to the server expire every hour.
356356
Therefore clients should expect the ``callback`` to fire at least once every hour, even if
357357
there are no updates in the database.

0 commit comments

Comments
 (0)
0