My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Firebase Send email verification using python

Budy mnvenom's photo
Budy mnvenom
·Oct 11, 2021·

1 min read

CHECK PREVIOUS TUTORIAL AND EXPLANATION Python and firebase auth Now to send an email verification using python. You need to send a POST request to

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

You need also the token that you get after sign in or sign up .

import requests

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

idToken='eyJh1pVjuYvfX72ewSqUxRNUNoGKgdhsaYdeOjs9OsQ......'#token

def VerifyEmail(idToken):
    headers = {
        'Content-Type': 'application/json',
    }
    data='{"requestType":"VERIFY_EMAIL","idToken":"'+idToken+'"}'
    r = requests.post('https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key={}'.format(apikey), headers=headers, data=data)
    if 'error' in r.json().keys():
        return {'status':'error','message':r.json()['error']['message']}
    if 'email' in r.json().keys():
        return {'status':'success','email':r.json()['email']}

run :

VerifyEmail(idToken)

result:

Success

{'status': 'success', 'email': 'user@example.com'}

The user will receive an email from you like this :

imageedit_4_5081572962.jpg Failed

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