How to integrate Microsoft User Authentication using Microsoft Entra ID: A Step-by-Step Guide to Use

  • Thread starter Thread starter HuzaifaGhori
  • Start date Start date
H

HuzaifaGhori

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.


large?v=v2&px=999.png





  • Search “Microsoft Entra ID

large?v=v2&px=999.png





  • Click on “Create

large?v=v2&px=999.png





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

large?v=v2&px=999.png













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

large?v=v2&px=999.png















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



large?v=v2&px=999.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

large?v=v2&px=999.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.



large?v=v2&px=999.png





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

large?v=v2&px=999.png











  • Click on “App registeration"

medium?v=v2&px=400.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.

large?v=v2&px=999.png







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

large?v=v2&px=999.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



large?v=v2&px=999.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



large?v=v2&px=999.png











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



medium?v=v2&px=400.png======>medium?v=v2&px=400.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.



large?v=v2&px=999.png





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



large?v=v2&px=999.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

large?v=v2&px=999.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

medium?v=v2&px=400.png=======>medium?v=v2&px=400.png









  • Enter the environment variables include “Tenant ID

large?v=v2&px=999.png



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



large?v=v2&px=999.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)

medium?v=v2&px=400.png============>medium?v=v2&px=400.png





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

large?v=v2&px=999.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.

Continue reading...
 
Back
Top