The role helicopters play in modern society

Niclas Herle is proud to part of the aviation industry as one of the figures at the forefront of the helicopter section. He is a pilot and a businessman and has helped many people through the use of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Connecting Django with Firebase Authentication

Firebase is a service created by google to help developers developing their apps. Firebase can store various data and helps store user information including authentication.

In this article we will be using Firebase for authentication in a Django app. First, we will create an account through Firebase Dashboard. We will discuss account creation through Django later.

Head to Firebase Dashboard > Authentication then press Add User and fill the email and password. Once you create an account, the UID will be generated automatically and Signed in field will be empty for now.

Next, we want to authenticate this newly created account through Django.

To send an authentication request to Firebase with Django, we will use the post method from requests library in python. We will send this request to firebase API and save the idToken that was given in return. This idToken will be saved in the client’s browser cookie and will be used to verify a user’s session. We can then show different part in the app that can only be accessed by an authenticated user by using the cookie that was saved. Some other method might be better and safer but this method will be enough for demonstration.

First, we need to create a form for the user’s sign in input by using the following code in both the views.py and index.html. In index.html we will use Django Template Language to show different text depending if the user is authenticated or not. In views.py we can use the cookie that was saved in the user’s browser to verify the user. You also need to add this view in urls.py

Once we’re done, we can test it if it works. If the authentication is successful, the page will not show the form again but will instead welcome the user. You can also see that in the Firebase Dashboard, the Signed in field is filled with the last login.

That is all! I hope this article is useful. Have a nice day!

Add a comment

Related posts:

Car Audio System

Whether you are travelling to work or to a restaurant to meet a friend, you use your car very often. While travelling short distances are still fine, travelling far away can get a bit boring. The…

Understanding the Value of Jewelry as an Investment.

Jewelry has long been considered a valuable asset, and many people view it as a wise investment. However, the value of jewelry as an investment can be a complex issue. In this article, we’ll explore…

Unknowable Space

It recalls the many secrets we kept Tossing our bodies together under our own endless black sky Sometimes a crack of thunder, sometimes the crash of my hand like waves and you bite into me and the…