Python Firebase auth (Sign up with email / password)

create a new user account on firebase Auth using python

Check Python firebase authentication Definitive guide (2021) for the full tutorial.

To create a new user account on firebase Auth using python you need to send a POST request to this URL

https://identitytoolkit.googleapis.com/v1/accounts:signUp

then if the registration succeeded we will get a token to use it later.

Don't panic it's all easy

This is how you do it in python using requests module.

import requests

apikey='.....................'# the web api key

def NewUser(email,password):
    details={
        'email':email,
        'password':password,
        'returnSecureToken': True
    }
    # send post request
    r=requests.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key={}'.format(apikey),data=details)
    #check for errors in result
    if 'error' in r.json().keys():
        return {'status':'error','message':r.json()['error']['message']}
    #if the registration succeeded
    if 'idToken' in r.json().keys() :
            return {'status':'success','idToken':r.json()['idToken']}

Now this is simple all you have to do is call the function like this :

NewUser('anemail@email.com','password')# use the email and the password

Output:

You will get something like this if everything is okay :

{'status': 'success',
 'idToken': 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjkwMDk1YmM2ZGM2ZDY3NzkxZDdkYTFlZWIxYTU1OWEzZDViMmM0ODYiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vaGFja2Vybm9vbi1hcHAiLCJhdWQiOiJoYWNrZXJub29uLWFwcCIsImF1dGhfdGltZSI6MTYzMDA4NTAwOSwidXNlcl9pZCI6Ilk0Q3luTHFVNVRRZGRSSE52MDRzWU54ZWFpdTIiL'}

or

{'status': 'error', 'message': 'EMAIL_EXISTS'}

it means that the email already registered.

Read more Python firebase authentication Definitive guide (2021)