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.

HuzaifaGhori_53-1718874069807.png

 

 

  • Search “Microsoft Entra ID

HuzaifaGhori_70-1718874195527.png

 

 

  • Click on “Create

HuzaifaGhori_71-1718874205972.png

 

 

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

HuzaifaGhori_73-1718874215254.png

 

 

 

 

 

 

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

HuzaifaGhori_76-1718874242917.png

 

 

 

 

 

 

 

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

 

HuzaifaGhori_79-1718874254235.png

 

 

 

  • 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

HuzaifaGhori_81-1718874261023.png

 

 

Congratulations! You have successfully created your first tenant.

 

 

  • How to Register app in MS Entra ID Tenant

Lets begin with the “App Registeration” Process.

 

HuzaifaGhori_5-1718875318956.png

 

 

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

HuzaifaGhori_6-1718875318974.png

 

 

 

 

 

  • Click on “App registeration"

HuzaifaGhori_8-1718875345371.png

 

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.

HuzaifaGhori_15-1718875417549.png

 

 

 

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

HuzaifaGhori_20-1718875444316.png

 

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

 

HuzaifaGhori_21-1718875464155.png

 

 

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

 

HuzaifaGhori_29-1718875580583.png

 

 

 

 

 

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

 

HuzaifaGhori_31-1718875611102.png======>HuzaifaGhori_32-1718875611118.png

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.

            

HuzaifaGhori_38-1718875892712.png

           

 

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

              

HuzaifaGhori_39-1718875973743.png

 

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

HuzaifaGhori_40-1718875997752.png

 

 

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

HuzaifaGhori_41-1718876036286.png=======>HuzaifaGhori_42-1718876036299.png

 

                    

 

 

  • Enter the environment variables include “Tenant ID

HuzaifaGhori_44-1718876111572.png

 

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

 

HuzaifaGhori_45-1718876160532.png

 

 

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

HuzaifaGhori_50-1718876193917.png============>HuzaifaGhori_51-1718876193936.png

 

 

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

HuzaifaGhori_53-1718876220321.png

 

 

  • We are all set lets run
    • python app.py

 

 

 

 

Conclusion:

  • 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.

 

 

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