How to integrate Microsoft User Authentication using Microsoft Entra ID: A Step-by-Step Guide to Use
Published Jun 27 2024 06:05 AM 1,711 Views
Copper Contributor

Greetings! It's Huzaifa Ghori and Microsoft Learn Student Ambassador from Karachi,Pakistan. I am in my senior of Computer Science Bachelors, from University of Karachi. Besides my studies I am a Python Developer and Data Engineer as well, I have a great skill set in development, including Front end Web, Backend, Chatbot Development, and also I give numerous services as a freelancer, I have started my technical writing here on techcommunity of Microsoft, I'll be sharing knowledge about Azure, cloud services, and many other micro services including integration with Python. So let's start today's blog


In this article we will be creating our tenant, resource and other services to use Microsoft Entra ID aka Azure AD, to create access management for only selected users at the end of this article you'll be able to create your own and also have the direction to take deep dive and more great implementation of this service.


In the fast-evolving landscape of digital identity management, Microsoft Entra stands out as a robust solution for secure authentication and streamlined access control. Whether you're a seasoned developer or a newcomer to the realm of identity services, this guide will walk you through the essential steps of setting up your application, creating user authentication, and empowering users with access privileges. Explore the power of Microsoft Entra and elevate your application's security and user management capabilities. Complete this step by step guide and use Microsoft Learn Module for further assistance and create your first User Access Management Using Microsoft Entra ID. In this guide we are going to learn:



Microsoft Entra ID, also known as Azure AD (Active Directory), offers numerous advantages. Whether you're prioritizing security or seeking a well-organized and automated User Management system, this tool is your go-to for building a secure authentication system, be it for a web app, mobile app, or any other application.

With Microsoft Entra ID, you gain not only security but also a host of other benefits. In this guide, we'll focus on creating a seamless sign-in experience. The registration process can sometimes be a bit tricky, but with Microsoft Entra ID, we'll simplify and handle it effortlessly from the portal.

So, if you're looking to make your application's authentication process secure, user-friendly, and seamlessly integrated, Microsoft Entra ID is the solution you've been searching for.

Lets Start !

  • How to create resource for Microsoft Entra ID

Starting by creating resource.




  • Search “Microsoft Entra ID




  • Click on “Create




  • Select “Microsoft Entra ID” then click “Next: Configuration” Button








  • Then Create Your Tenant fill out the the Details mentioned in the form.
  • Cilck on “Review + create”.









  • On the final screen wait for the validation passed Notification then click on “Create






  • After completing this step the side pane will appear to complete the captcha after completing it you have to wait for some minutes for your tenant creation it will give the notification about the succesfull creation of tenant




Congratulations! You have successfully created your first tenant.



  • How to Register app in MS Entra ID Tenant

Lets begin with the “App Registeration” Process.





  • Click on the “+ Add” button appearing in the resource navigations







  • Click on “App registeration"



On the appeared screen fill out the form

  • Type the display name of your application (can be changed later)
  • Select Single Tenant.
  • Now in Redirect URI section select your application type in my case its website and Enter the URL where application will redirect user after authenticating you can enter URL later its optional so I am leaving it blank for now.
  • Click on Register Button.





Congrats! You have successfully Registered your first app in your first tenant.



Is this it? Nope Guys we are just around the corner be patient.

Lets follow quickstart to create our very first Authentication System using Microsoft services.


  • Go to quick start in left sidebar below Overview option click on “Quickstart





Is this it? Nope Guys we are just around the corner be patient.

Lets follow quickstart to create our very first Authentication System using Microsoft services.


  • Go to quick start in left sidebar below Overview option click on “Quickstart








  • In the Quick Start Page select your preferred technology of application in my case its Python Flask web application.



Note: We are only 3 steps ahead from our first app with authentication system using MS Services.


  • Following Quick Start integrating Microsoft User Authentication

Lets quickly complete 3 steps and test our application

Step 1: Configure your application in Azure portal

For the code sample in this quickstart to work:

Either you can do it manually or can click on button “Make these changes for me” appears in quickstart tab to complete this automatically.





After clicking on button for automated process it will return you a client secret save it to enter in code later.




Step 2: Download your project or clone it from my GitHub

  • Download or clone the project and if download, extract the zip file to a local folder or clone, closer to the root folder - for example, C:\Azure-Samples




Step 3: Made the following changes in the code and run

  1. You will need to install MSAL Python library, Flask framework, Flask-Sessions for server-side session management and requests using pip as follows:
  • pip install -r requirements.txt


  1. Open folder in the vs code and made the following changes
  • Change the name of “.env.sample” to “.env






  • Enter the environment variables include “Tenant ID



  • Note: You can find your “TENANT ID” and “CLIENT ID” in the over view tab of your “App Registeration





  • In at the very last line you can find this command “” change it to “"localhost", port=5000)




  • In add metioned below lines in the beginning of file
  • import dotenv
  • dotenv.load_dotenv()




  • We are all set lets run
    • python






  • As we conclude this guide on mastering Microsoft Entra, you now possess the knowledge to enhance your application's security and streamline user management. But our journey doesn't end here – it's just the beginning. Follow the Microsoft Learn Modules to Learn More about Microsoft Entra:
  • Understand Microsoft Entra ID
  • Register apps using Microsoft Entra ID
  • Implement app registration
  • Your Next Step: In the upcoming blog, we'll delve into the pivotal process of adding users to your app registration for seamless access provisioning. Learn how to empower users with tailored privileges, ensuring a dynamic and secure user experience. Click here to stay tuned for our next installment and continue your exploration of Microsoft Entra's capabilities.
  • Stay Connected: Feel free to connect with me on LinkedIn for further discussions or follow on Instagram to stay updated with the latest tech insights. I'm here to assist, so don't hesitate to reach out for any queries or clarifications. Your engagement is valued, and I look forward to connecting with you on this exciting journey. Thank you for being part of this transformative experience.



Version history
Last update:
‎Jun 20 2024 03:05 AM
Updated by: