Skip to content

Add auth bulk get/delete snippets #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions snippets/auth/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ def get_user_by_email():
print('Successfully fetched user data: {0}'.format(user.uid))
# [END get_user_by_email]

def bulk_get_users():
# [START bulk_get_users]
from firebase_admin import auth

result = auth.get_users([
auth.UidIdentifier('uid1'),
auth.EmailIdentifier('[email protected]'),
auth.PhoneIdentifier(+15555550003),
auth.ProviderIdentifier('google.com', 'google_uid4')
])

print('Successfully fetched user data:')
for user in result.users:
print(user.uid)

print('Unable to find users corresponding to these identifiers:')
for uid in result.not_found:
print(uid)
# [END bulk_get_users]

def get_user_by_phone_number():
phone = '+1 555 555 0100'
# [START get_user_by_phone]
Expand Down Expand Up @@ -242,6 +262,18 @@ def delete_user(uid):
print('Successfully deleted user')
# [END delete_user]

def bulk_delete_users():
# [START bulk_delete_users]
from firebase_admin import auth

result = auth.delete_users(["uid1", "uid2", "uid3"])

print('Successfully deleted {0} users'.format(result.success_count))
print('Failed to delete {0} users'.format(result.failure_count))
for err in result.errors:
print('error #{0}, reason: {1}'.format(result.index, result.reason))
# [END bulk_delete_users]

def set_custom_user_claims(uid):
# [START set_custom_user_claims]
# Set admin privilege on the user corresponding to uid.
Expand Down