In this Python Firebase article iam going to talk about Firebase Authentication with Email & Password, so before this i had an article about Python Firebase, on that article we have talked about Real Time Database.
1: Python Firebase Working With Real Time Database
What is Firebase Authentication ?
Most apps need to know the identity of a user. Knowing a user’s identity allows an app to securely save user data in the cloud and provide the same personalized experience across all of the user’s devices.
Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.
Firebase Authentication integrates tightly with other Firebase services, and it leverages industry standards like OAuth 2.0 and OpenID Connect, so it can be easily integrated with your custom backend.
So in this article we are going to use pyrebase library, pyrebase is a simple python wrapper for the Firebase API.
Installation
You can install pyrebase easily by pip3 install pyrebase, if it does not works like this, so firs you need
to upgrade some libraries like this .
1 |
pip3 install --upgrade setuptools |
1 |
pip3 install --upgrade gcloud |
1 |
pip3 install pyrebase |
Getting Started
For use with only user based authentication we can create the following configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import pyrebase firebaseConfig = { "apiKey": "YOUR API KEY", "authDomain": "mytest-91572.firebaseapp.com", "databaseURL": "https://mytest-91572.firebaseio.com", "projectId": "mytest-91572", "storageBucket": "mytest-91572.appspot.com", "messagingSenderId": "558021857077", "appId": "1:558021857077:web:63b4ff6e71edb9211bc67c", "measurementId": "G-HL4NZ8QSN9" } firebase = pyrebase.initialize_app(firebaseConfig) |
User Services
A Pyrebase app can use multiple Firebase services.
firebase.auth()
– Authentication
firebase.database()
– Database
firebase.storage()
– Storage
Check out the documentation for each service for further details.
So now this is the complete code for Python Firebase Authentication with Email & Password
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 |
import pyrebase from getpass import getpass firebaseConfig = { "apiKey": "YOUR API KEY", "authDomain": "mytest-91572.firebaseapp.com", "databaseURL": "https://mytest-91572.firebaseio.com", "projectId": "mytest-91572", "storageBucket": "mytest-91572.appspot.com", "messagingSenderId": "558021857077", "appId": "1:558021857077:web:63b4ff6e71edb9211bc67c", "measurementId": "G-HL4NZ8QSN9" } firebase = pyrebase.initialize_app(firebaseConfig) auth = firebase.auth() email = input("Please Enter Your Email Address : \n") password = getpass("Please Enter Your Password : \n") #create users user = auth.create_user_with_email_and_password(email, password) print("Success .... ") login = auth.sign_in_with_email_and_password(email, password) #send email verification auth.send_email_verification(login['idToken']) #reset the password auth.send_password_reset_email(email) print("Success ... ") |
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email