# FireBase Auth
Este módulo permite manejar distintos métodos de Firebase Authentication (opens new window) para la gestión de usuarios.
Si va a utilizar Firebase Auth (opens new window) en un servidor personalizado, ó en modo local, recuerde utilizar una cuenta de servicio (opens new window)
# Funciones disponibles
La clase FirebaseAuth, implementada en el BackEndBase contiene las siguientes funciones:
get_list_users
create_user
create_user_with_phone
get_user_by_uuid
get_user_by_email
get_user_by_phone_number
update_user
delete_user
delete_massive_users
disable_user
enable_user
password_reset_link
email_verification_link
# get_list_users
@staticmethod
def get_list_users():
...
# create_user
@staticmethod
def create_user(user_data):
...
# create_user_with_phone
@staticmethod
def create_user_with_phone(user_data):
...
# get_user_by_uuid
@staticmethod
def get_user_by_uuid(uid, to_json=False):
...
# get_user_by_email
@staticmethod
def get_user_by_email(email):
...
# get_user_by_phone_number
@staticmethod
def get_user_by_phone_number(phone):
...
# update_user
@staticmethod
def update_user(uid, user_data):
...
# delete_user
@staticmethod
def delete_user(uid):
...
# delete_massive_users
@staticmethod
def delete_massive_users(user_uid_list):
...
# disable_user
@staticmethod
def disable_user(uid):
...
# enable_user
@staticmethod
def enable_user(uid):
...
# password_reset_link
@staticmethod
def password_reset_link(email):
...
# email_verification_link
@staticmethod
def email_verification_link(email):
...
# Un ejemplo
from app.ext.rest import Rest, HttpStatus
from app.ext.firebase.firestore_auth import FirebaseAuth
...
uid ="0TBbkaf95EQ8U9caAeXrF1zWSjx1"
user_to_find = FirebaseAuth.get_user_by_uuid(uid, True)
if user_to_find is not None:
return Rest.response(200, HttpStatus.OK, user_to_find)
else:
return Rest.response(400, HttpStatus.UNEXPECTED_ERROR, errors=HttpStatus.RESOURCE_NOT_EXIST)
El resultado del ejemplo anterior:
{
"data": {
"createdAt": "1588006809836",
"lastLoginAt": "1588006809836",
"lastRefreshAt": "2020-04-28T16:56:24.117Z",
"localId": "0TBbkaf95EQ8U9caAeXrF1zWSjx1"
},
"message": "success!",
"status": 200
}
Los resultados varían en caso de que sea un usuario registrado de forma anónima, ó con un proveedor (opens new window)
{
"data": {
"createdAt": "1582726232453",
"disabled": false,
"displayName": "Jhon Doe",
"email": "jhondoe@awesomeapp.com",
"emailVerified": false,
"lastLoginAt": "1592494975788",
"lastRefreshAt": "2020-06-18T23:58:51.568Z",
"localId": "2FIfohMcp8l5s0hW0kz68UpTn3v2",
"passwordHash": "-Xvt4kjecEpKAmEA-r4tyqLcdwSdGxWXHzj6es-FWgJCngRPAAhTd_1e7kVGLXODlQIyMmQ0o0HRYYByeAVwxA==",
"passwordUpdatedAt": 1582726232453,
"phoneNumber": "+573123456789",
"providerUserInfo": [
{
"phoneNumber": "+573123456789",
"providerId": "phone",
"rawId": "+573123456789"
},
{
"displayName": "Jhon Doe",
"email": "jhondoe@awesomeapp.com",
"federatedId": "jhondoe@awesomeapp.com",
"providerId": "password",
"rawId": "jhondoe@awesomeapp.com"
}
],
"salt": "dGxWXHzj6==",
"validSince": "1582726232",
"version": 0
},
"message": "success!",
"status": 200
}
# Más información
Para mas información consulte:
- API de administración de Firebase (opens new window)
- Administra usuarios con Firebase (opens new window)
- Referencia del SDK (opens new window)
- La sección de issues (opens new window) del BackEndBase