5

I'm making a KivyMD App and I want to send email verification code when an user is registered to the application. I'm using a firestore database with python for this project. But I don't have an idea to do that. The registration process is

  1. User sign up to the application with his email address.
  2. an email contains a code (with random numbers - OTP Code) should be send to the user's email.
  3. After user enters the correct verification code he should be registered in the application.

Can this be done with the way I expected? Or are there other better ways? Please help me Friends. Thank you in advance...

Kusal Darshana
  • 159
  • 2
  • 18
  • Do you have a different backend implementation for the email delivery ? are you limited on firebase products or you are willing to include cloud functions ? – KE Keronei Nov 25 '21 at 05:53
  • 1
    Have you looked at this: https://dev.to/xbudy/firebase-send-email-verification-using-python-32hp – ObjectJosh Dec 01 '21 at 00:27

2 Answers2

1

In order to send verification link on email you have to setup smpt server

import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth
import smtplib
s = smtplib.SMTP('protonmail.com', 1025)
s.starttls()
s.login("your email", "pass0")
cred = credentials.Certificate('you_Secret.json')
firebase_admin.initialize_app(cred)


# creating the user
email = input('Please enter your email address : ')
password = input("Please enter your password : ")

user = auth.create_user(email=email, password=password )
link = auth.generate_email_verification_link(email, action_code_settings=None)
message = link
print(link)
s.sendmail("sender email", "reciever email", message)

# terminating the session
s.quit()

OUTPUT

link:https://hospitile.firebaseapp.com/__/auth/action?mode=verifyEmail&oobCode=_yM6YyEBt7e5Fyokjpbt4EUMw4eZzAe41n-t2oS-tNYAAAF9eZ-hnQ&apiKey=AIzaSyBJld5O_s09YVHoQ0ci7g3N3S-0DYjuH0U&lang=en

enter image description here

And when you click on that link you will be prompted to new tab below

enter image description here

loopassembly
  • 2,653
  • 1
  • 15
  • 22
  • Hello, how would I go about sending verification emails without having to create a new account each time? For example, a user could have deleted the email. In this scenario, how could the email be resent? – jeff Jun 25 '22 at 22:03
  • hey, @jeff the problem which u stated above can be resolved by making a function that would call the SMTP server every time u make an action using the button/link to resend the email but first make sure that the user already has an account authenticated on firebase. – loopassembly Jun 26 '22 at 07:00
  • Would I need to use the same flow as what you have about in your code? That said, it seems like I could inject the code you have above in some area of my API. However, it seems that I would still need a third-party SMTP provider, is that correct? – jeff Jul 04 '22 at 21:17
  • probably yes, but if ur making rest API then it is too simple like the framework ur are using for eg node, Django, etc they have preloaded SMTP so u can take that in use, and it would be less complicated too. – loopassembly Jul 06 '22 at 07:23
  • Hahah, yea. I actually just finished implementing this flow with SendGrid. They have their own functionality to handle the SMTP stuff which is really nice, so I didn't even have to use the frameworks built-in stuff. – jeff Jul 06 '22 at 22:37
  • that's great good luck – loopassembly Jul 07 '22 at 07:21
0

Have you found the Firebase Python documentation? https://firebase.google.com/docs/reference/admin/python/firebase_admin.auth#generate_email_verification_link

It has explanations for the necessary functions to generate email verification links.

firebase_admin.auth.generate_email_verification_link(email, action_code_settings=None, app=None)
oittaa
  • 599
  • 3
  • 16