-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy path_user_identifier.py
103 lines (75 loc) · 2.66 KB
/
_user_identifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Classes to uniquely identify a user."""
from firebase_admin import _auth_utils
class UserIdentifier:
"""Identifies a user to be looked up."""
class UidIdentifier(UserIdentifier):
"""Used for looking up an account by uid.
See ``auth.get_user()``.
"""
def __init__(self, uid):
"""Constructs a new `UidIdentifier` object.
Args:
uid: A user ID string.
"""
self._uid = _auth_utils.validate_uid(uid, required=True)
@property
def uid(self):
return self._uid
class EmailIdentifier(UserIdentifier):
"""Used for looking up an account by email.
See ``auth.get_user()``.
"""
def __init__(self, email):
"""Constructs a new `EmailIdentifier` object.
Args:
email: A user email address string.
"""
self._email = _auth_utils.validate_email(email, required=True)
@property
def email(self):
return self._email
class PhoneIdentifier(UserIdentifier):
"""Used for looking up an account by phone number.
See ``auth.get_user()``.
"""
def __init__(self, phone_number):
"""Constructs a new `PhoneIdentifier` object.
Args:
phone_number: A phone number string.
"""
self._phone_number = _auth_utils.validate_phone(phone_number, required=True)
@property
def phone_number(self):
return self._phone_number
class ProviderIdentifier(UserIdentifier):
"""Used for looking up an account by provider.
See ``auth.get_user()``.
"""
def __init__(self, provider_id, provider_uid):
"""Constructs a new `ProviderIdentifier` object.
Args:
provider_id: A provider ID string.
provider_uid: A provider UID string.
"""
self._provider_id = _auth_utils.validate_provider_id(provider_id, required=True)
self._provider_uid = _auth_utils.validate_provider_uid(
provider_uid, required=True)
@property
def provider_id(self):
return self._provider_id
@property
def provider_uid(self):
return self._provider_uid