<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shahzada Fahad Ashraf</title>
    <description>The latest articles on DEV Community by Shahzada Fahad Ashraf (@fahadachaudhry).</description>
    <link>https://dev.to/fahadachaudhry</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F713203%2Fa9e05a2f-6eb4-46fc-8f17-c76a028c560b.jpg</url>
      <title>DEV Community: Shahzada Fahad Ashraf</title>
      <link>https://dev.to/fahadachaudhry</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fahadachaudhry"/>
    <language>en</language>
    <item>
      <title>Silly Javascript, says true when asked if (0 == -null); here's why...</title>
      <dc:creator>Shahzada Fahad Ashraf</dc:creator>
      <pubDate>Thu, 01 Feb 2024 06:42:04 +0000</pubDate>
      <link>https://dev.to/fahadachaudhry/silly-javascript-says-true-when-asked-if-0-null-heres-why-59l4</link>
      <guid>https://dev.to/fahadachaudhry/silly-javascript-says-true-when-asked-if-0-null-heres-why-59l4</guid>
      <description>&lt;p&gt;JavaScript is a versatile programming language known for its flexibility, but this flexibility sometimes leads to interesting behaviors.&lt;/p&gt;

&lt;p&gt;For instance, try running the following code in your dev console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuj1j5u19q4jdyz9vjto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuj1j5u19q4jdyz9vjto.png" alt="Console Screenshot" width="800" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Strange, right? Well, JavaScript behaves this way due to a concept called &lt;strong&gt;type coercion&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Coercion
&lt;/h2&gt;

&lt;p&gt;Type coercion is the automatic conversion of one data type to another, often performed in JavaScript during operations involving different types. The loose equality operator (==) triggers type coercion, attempting to make the operands comparable. &lt;/p&gt;

&lt;p&gt;In the given expression, the left operand is the number 0, while the right operand involves coercing null to a number. When null is coerced to a number, it results in the value 0. Therefore, the expression essentially becomes 0 == 0.&lt;/p&gt;

&lt;p&gt;This outcome might seem surprising at first glance, as one might expect the comparison to be false due to the explicit difference between 0 and -0. However, it is essential to recognize that -null is not equivalent to negative zero but rather zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  But, why exactly?
&lt;/h2&gt;

&lt;p&gt;Understanding the mechanics behind this behavior requires insight into JavaScript's type coercion rules. The language attempts to find a common type between the operands, prioritizing numeric values. In this case, the coercion of null to a number yields 0, aligning both sides of the equality check.&lt;/p&gt;

&lt;p&gt;While this behavior may be convenient in certain scenarios, it highlights the importance of caution when using loose equality (==) in JavaScript. Developers often prefer the strict equality operator (===), which compares both value and type, avoiding unexpected type coercion and promoting more predictable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The expression 0 == -null in JavaScript showcases the language's type coercion mechanisms. Through automatic conversion, JavaScript aligns the operands by coercing null to a number, resulting in the equality check 0 == 0. This example serves as a reminder of the nuanced aspects of JavaScript's loose equality operator and the importance of understanding type coercion for writing robust and predictable code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>interview</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript's Single-Threaded Bliss: Because Who Needs Multithreading Anyway</title>
      <dc:creator>Shahzada Fahad Ashraf</dc:creator>
      <pubDate>Wed, 31 Jan 2024 08:15:53 +0000</pubDate>
      <link>https://dev.to/fahadachaudhry/javascripts-single-threaded-bliss-because-who-needs-multithreading-anyway-1d53</link>
      <guid>https://dev.to/fahadachaudhry/javascripts-single-threaded-bliss-because-who-needs-multithreading-anyway-1d53</guid>
      <description>&lt;p&gt;JavaScript is a single-threaded, non-blocking, and asynchronous programming language. This means that it has only one execution thread, but it can handle asynchronous operations efficiently without blocking the execution of the entire program. This is achieved through a mechanism called the event loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Loop:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExZTA1ZmZ2aXN4YzdlNDJjZW43Y2pweHpkZnMwMTkwZ2FuaTJ1bTJxNSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/2Fazad9Hs5xPAF6iQ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExZTA1ZmZ2aXN4YzdlNDJjZW43Y2pweHpkZnMwMTkwZ2FuaTJ1bTJxNSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/2Fazad9Hs5xPAF6iQ/giphy.gif" alt="Event Loop" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event loop is a crucial part of JavaScript's &lt;strong&gt;concurrency model&lt;/strong&gt;. It continuously checks the execution queue (also called the message queue) for new messages and processes them one by one.&lt;br&gt;
The execution queue is a data structure that holds messages or events with their associated callback functions.&lt;/p&gt;
&lt;h2&gt;
  
  
  Callback Queue:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExZndlbDdsYXg5b2czcnhvN3FudWNwbmM4NG93cHEwZ3BkZjR0dndtcCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/35Kf7OnQCkPj2Ojtf6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExZndlbDdsYXg5b2czcnhvN3FudWNwbmM4NG93cHEwZ3BkZjR0dndtcCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/35Kf7OnQCkPj2Ojtf6/giphy.gif" alt="Callback Queue" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When an asynchronous operation completes (such as a network request, a file read, or a timer), a message containing the associated callback function is placed in the callback queue.&lt;/p&gt;
&lt;h2&gt;
  
  
  Execution Stack:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExczdpb2VwOXJ6bTkxaHNya2ZtY3B2OXJmdHZyYThqajE5NTNvb2l5eSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/eG53NgJaxNHpJhldVx/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExczdpb2VwOXJ6bTkxaHNya2ZtY3B2OXJmdHZyYThqajE5NTNvb2l5eSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/eG53NgJaxNHpJhldVx/giphy.gif" alt="Callback Queue" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The execution stack is a stack data structure that keeps track of the currently executing functions. When a function is called, it is pushed onto the stack. When it completes, it is popped off the stack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Non-Blocking Nature:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdGdyY2Y5MW5xYTRlYnlrMzUyb3E2dTBwZWFjOWZvbWE1ZTgwaDk4bCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Sv9Z6bLestCgsyR7A9/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdGdyY2Y5MW5xYTRlYnlrMzUyb3E2dTBwZWFjOWZvbWE1ZTgwaDk4bCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Sv9Z6bLestCgsyR7A9/giphy.gif" alt="Non-Blocking Nature" width="480" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is non-blocking, meaning that while an asynchronous operation is in progress, the program doesn't wait for it to complete. Instead, it continues to execute other tasks.&lt;/p&gt;

&lt;p&gt;JavaScript relies heavily on event-driven programming. Events, such as user interactions or the completion of asynchronous operations, trigger the execution of associated callback functions.&lt;/p&gt;

&lt;p&gt;Here's a simple example to illustrate the event loop in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Start");

// Asynchronous operation (simulated with setTimeout)
setTimeout(function () {
  console.log("Async operation completed");
}, 2000);

console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "Start" and "End" messages will be logged immediately, and the asynchronous operation in setTimeout will be scheduled. The event loop will continue running, and after approximately 2 seconds, the callback function inside setTimeout will be pushed into the message queue and executed, logging "Async operation completed."&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---FFproBc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--dhjH4Wt---/c_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_800/https://devtolydiahallie.s3-us-west-1.amazonaws.com/gif14.1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---FFproBc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--dhjH4Wt---/c_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_800/https://devtolydiahallie.s3-us-west-1.amazonaws.com/gif14.1.gif" alt="Conclusion" width="720" height="405"&gt;&lt;/a&gt;&lt;br&gt;
(Illustration taken from &lt;a href="https://dev.to/lydiahallie/javascript-visualized-event-loop-3dif"&gt;https://dev.to/lydiahallie/javascript-visualized-event-loop-3dif&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;This mechanism allows JavaScript to efficiently handle asynchronous tasks without blocking the main thread, making it suitable for tasks like handling user interactions, making network requests, and managing I/O operations.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>interview</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tackling React's Most Loathed Interview Question - Diffing and Reconciliation Unveiled</title>
      <dc:creator>Shahzada Fahad Ashraf</dc:creator>
      <pubDate>Tue, 30 Jan 2024 07:23:14 +0000</pubDate>
      <link>https://dev.to/fahadachaudhry/tackling-reacts-most-loathed-interview-question-diffing-and-reconciliation-unveiled-4pcd</link>
      <guid>https://dev.to/fahadachaudhry/tackling-reacts-most-loathed-interview-question-diffing-and-reconciliation-unveiled-4pcd</guid>
      <description>&lt;p&gt;In this article series where we focus on some of the most asked React Interview questions, is about time we discussed whatever the heck the Diffing Algorithm is!&lt;/p&gt;

&lt;p&gt;React is a popular JavaScript library for building user interfaces, of course, this we already knew.&lt;br&gt;
However, to efficiently update the DOM and ensure optimal performance, React employs an algorithm that is responsible for detecting any changes made to the DOM and running a process called the "reconciliation process" that reflects these changes on the DOM. This algorithm is called the "Diffing Algorithm".&lt;/p&gt;

&lt;h2&gt;
  
  
  Diffing Algorithm:
&lt;/h2&gt;

&lt;p&gt;At the core, React's diffing algorithm is responsible for determining the difference between the current Virtual DOM (representing the UI state) and the updated Virtual DOM after a state change. This process helps React identify the minimal set of changes needed to update the actual DOM, thereby enhancing performance.&lt;/p&gt;

&lt;p&gt;The algorithm follows a strategy known as "tree reconciliation." It traverses the Virtual DOM trees and performs a depth-first search to identify differences between corresponding elements. React's reconciliation algorithm aims to minimize the number of DOM manipulations required to reflect the updated state, making the UI update process more efficient.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Steps in the Diffing Algorithm:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Element Identification:&lt;/strong&gt;&lt;br&gt;
React assigns a unique key to each element in the Virtual DOM, aiding in efficient identification during the diffing process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tree Comparison:&lt;/strong&gt;&lt;br&gt;
The algorithm compares corresponding elements in the old and new Virtual DOM trees, looking for differences.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Component-Level Reconciliation:&lt;/strong&gt;&lt;br&gt;
React optimizes the process by understanding the structure of components. It prioritizes updating components over individual elements to minimize unnecessary changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reordering Elements:&lt;/strong&gt;&lt;br&gt;
When elements are reordered, React efficiently updates the order in the actual DOM rather than re-rendering each element.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Reconciliation Process:
&lt;/h2&gt;

&lt;p&gt;Once the differences are identified through the diffing algorithm, React initiates the reconciliation process to update the actual DOM. The goal is to make the actual DOM mirror the updated Virtual DOM with minimal modifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/fahadachaudhry/reacts-virtual-dom-unveiling-the-engine-behind-lightning-fast-web-applications-nfm"&gt;Read more about the Virtual DOM here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Aspects of Reconciliation:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOM Updates:&lt;/strong&gt;&lt;br&gt;
React updates only the parts of the DOM that have changed, avoiding unnecessary re-renders and promoting a more efficient rendering process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lifecycle Methods:&lt;/strong&gt;&lt;br&gt;
React invokes lifecycle methods like &lt;code&gt;componentDidUpdate&lt;/code&gt; or in the modern versions, certain hooks, such as &lt;code&gt;useEffect&lt;/code&gt; to allow developers to perform additional logic after a component updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keyed Elements:&lt;/strong&gt;&lt;br&gt;
Properly utilizing keys for elements enhances the efficiency of the reconciliation process, preventing unnecessary re-renders and ensuring accurate updates.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Understanding React's diffing algorithm and reconciliation process is crucial for optimizing performance in React applications. By efficiently identifying and updating only the necessary parts of the DOM, React ensures a smooth and responsive user interface, making it a powerful choice for building dynamic web applications.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>React's Virtual DOM: Unveiling the Engine Behind Lightning-Fast Web Applications</title>
      <dc:creator>Shahzada Fahad Ashraf</dc:creator>
      <pubDate>Mon, 29 Jan 2024 11:08:43 +0000</pubDate>
      <link>https://dev.to/fahadachaudhry/reacts-virtual-dom-unveiling-the-engine-behind-lightning-fast-web-applications-nfm</link>
      <guid>https://dev.to/fahadachaudhry/reacts-virtual-dom-unveiling-the-engine-behind-lightning-fast-web-applications-nfm</guid>
      <description>&lt;h1&gt;
  
  
  Understanding the Virtual DOM in React
&lt;/h1&gt;

&lt;p&gt;React, a popular JavaScript library for building user interfaces introduces a concept called the Virtual DOM, which plays a crucial role in optimizing performance and improving the efficiency of web applications. For someone with little to no experience with React, understanding the Virtual DOM is key to grasping the framework's inner workings.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Virtual DOM?
&lt;/h2&gt;

&lt;p&gt;In traditional web development, whenever there is a change in the data that needs to be reflected in the user interface, the entire HTML structure is regenerated. &lt;strong&gt;This process is resource-intensive and can lead to slower performance, especially in complex applications.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React addresses this issue by introducing the Virtual DOM. &lt;strong&gt;The Virtual DOM is a lightweight, in-memory representation of the actual DOM (Document Object Model).&lt;/strong&gt; Instead of directly manipulating the real DOM, React creates and manipulates this virtual representation first.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;When the state of a React component changes, React doesn't immediately update the DOM. Instead, it first updates the Virtual DOM. This Virtual DOM is a tree structure mirroring the actual DOM. React then compares the previous Virtual DOM with the updated one, identifying the specific changes that occurred.&lt;/p&gt;

&lt;p&gt;Once React determines the changes, it calculates the most efficient way to update the real DOM and applies only those necessary changes. This process is known as "reconciliation." By updating only the parts of the DOM that have changed, React minimizes the performance impact, resulting in faster and more efficient updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of the Virtual DOM
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance Optimization:&lt;/strong&gt; The Virtual DOM significantly reduces the amount of direct manipulation of the real DOM, leading to faster rendering and improved application performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficient Updates:&lt;/strong&gt; React's ability to calculate and apply only the necessary changes to the DOM reduces the overall workload, especially in large and complex applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Declarative Syntax:&lt;/strong&gt; React's declarative syntax, where developers describe the desired outcome rather than the step-by-step process, works seamlessly with the Virtual DOM, making code more readable and maintainable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-browser Consistency:&lt;/strong&gt; React abstracts away the differences in browser implementations, providing a consistent development experience across various browsers.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In summary, the Virtual DOM in React is a fundamental concept that enhances the efficiency and performance of web applications. By employing a virtual representation of the DOM and intelligently updating only the necessary parts, React ensures a smooth and responsive user experience, making it a powerful and developer-friendly framework for building modern web applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>How to Integrate Azure Active Directory B2C in ASP.NET 4.5 WebAPI</title>
      <dc:creator>Shahzada Fahad Ashraf</dc:creator>
      <pubDate>Sun, 30 Jul 2023 16:01:21 +0000</pubDate>
      <link>https://dev.to/fahadachaudhry/how-to-integrate-azure-active-directory-b2c-in-aspnet-45-webapi-1eep</link>
      <guid>https://dev.to/fahadachaudhry/how-to-integrate-azure-active-directory-b2c-in-aspnet-45-webapi-1eep</guid>
      <description>&lt;h3&gt;
  
  
  Hey there, my fellow tech-savvy readers!
&lt;/h3&gt;

&lt;p&gt;Now, picture this: &lt;em&gt;you've got a trusty ASP.NET 4.5 WebAPI application chugging along like a well-oiled machine,&lt;/em&gt; doing its thing, and you're thinking, "Why change something that works just fine?" 💼🕶️ &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But as the tech world evolves faster than a cheetah chasing its morning coffee,&lt;/strong&gt; I started feeling the pressure once I set sails to incorporate Azure Active Directory B2C into my relatively older codebase. 💨☁️ &lt;/p&gt;

&lt;p&gt;&lt;em&gt;And there's the rub! 🌶️ Integrating ADB2C into this tried-and-true ASP.NET version came to me like introducing a jazz band to a black-tie ball. 😂🎷&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But fear not as I'm here to help you navigate these waters with a smile on your face and a skip in your step. 💃🕺 &lt;/p&gt;

&lt;p&gt;I'll show you how to combine the old and the new in a seamless dance that'll make your ASP.NET 4.5 WebAPI look and feel like it's on cloud nine! ☁️💫 &lt;/p&gt;

&lt;p&gt;So grab your coding wands, and let's sprinkle some Azure Active Directory B2C fairy dust over your beloved ASP.NET 4.5 WebAPI! 🧙‍♂️✨&lt;/p&gt;

&lt;h2&gt;
  
  
  Assumptions
&lt;/h2&gt;

&lt;p&gt;At this point, I'm assuming the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You have already set up your Azure Account&lt;/li&gt;
&lt;li&gt;You already have the necessary information and credentials required to create the hand-shake between Azure and your ASP.NET App&lt;/li&gt;
&lt;li&gt;You have already defined scopes, and policies&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1
&lt;/h2&gt;

&lt;p&gt;Start by adding the necessary credentials and information in your Web.config file. Per my experience, you're going to be needing the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;add key="AZB2C:AadInstance" value="https://&amp;lt;YOUR_AZURE_DOMAIN&amp;gt;.b2clogin.com/{0}/{1}/v2.0/.well-known/openid-configuration" /&amp;gt;
&amp;lt;add key="AZB2C:Tenant" value="&amp;lt;YOUR_AZURE_DOMAIN&amp;gt;.onmicrosoft.com" /&amp;gt;
&amp;lt;add key="AZB2C:TenantId" value="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" /&amp;gt;
&amp;lt;add key="AZB2C:ClientId" value="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" /&amp;gt;
&amp;lt;add key="AZB2C:ClientSecret" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" /&amp;gt;
&amp;lt;add key="AZB2C:RedirectUri" value="http://localhost:3000/" /&amp;gt;
&amp;lt;add key="AZB2C:SignUpSignInPolicyId" value="SIGN_IN_POLICY_NAME" /&amp;gt;
&amp;lt;add key="AZB2C:ResetPasswordPolicyId" value="PASSWORD_RESET_POLICY_NAME" /&amp;gt;
&amp;lt;add key="AZB2C:SOME_SCOPE_NAME" value="Scope.Something.Something" /&amp;gt;
&amp;lt;add key="AZB2C:ANOTHER_SCOPE_NAME" value="Scope.Yes.AnotherSomething" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are going to be basing our code off of these credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2
&lt;/h2&gt;

&lt;p&gt;Create a *&lt;em&gt;civilized *&lt;/em&gt; way of using these environment variables in your code by creating a static class that extracts all the env variables from the Web.config into a Static Class Instance. This way, you can easily access these environment variables all across your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public static class AzureEnvironmentVariables
    {
        public static string AadInstance = ConfigurationManager.AppSettings["AZB2C:AadInstance"];
        public static string Tenant = ConfigurationManager.AppSettings["AZB2C:Tenant"];
        public static string TenantId = ConfigurationManager.AppSettings["AZB2C:TenantId"];

        public static string ClientId = ConfigurationManager.AppSettings["AZB2C:ClientId"];
        public static string ClientSecret = ConfigurationManager.AppSettings["AZB2C:ClientSecret"];
        public static string RedirectUri = ConfigurationManager.AppSettings["AZB2C:RedirectUri"];

        public static string SignUpSignInPolicyId = ConfigurationManager.AppSettings["AZB2C:SignUpSignInPolicyId"];
        public static string ResetPasswordPolicyId = ConfigurationManager.AppSettings["AZB2C:ResetPasswordPolicyId"];

        public static string DefaultPolicy = SignUpSignInPolicyId;

        public static string FirstScope = AadInstance + ConfigurationManager.AppSettings["api:SOME_SCOPE_NAME"];
        public static string SecondScope = AadInstance + ConfigurationManager.AppSettings["api:ANOTHER_SCOPE_NAME"];
        public static string[] Scopes = new string[] { FirstScope, SecondScope };

        public static string B2CAuthority = string.Format(AadInstance, Tenant, DefaultPolicy);
        public static string WellKnownMetadata = $"{AadInstance}/v2.0/.well-known/openid-configuration?p={SignUpSignInPolicyId}";
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create your auth provider
&lt;/h3&gt;

&lt;p&gt;No go ahead and create a new file in your &lt;code&gt;App_Start&lt;/code&gt; folder called &lt;code&gt;Startup.Auth.cs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this file, you are going to create a Startup Extension Method that will be triggered on Startup time and register your Auth Provider, called Startup.Auth into your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public partial class Startup
    {
        public static string AadInstance = AzureEnvironmentVariables.AadInstance;
        public static string Tenant = AzureEnvironmentVariables.Tenant;
        public static string TenantId = AzureEnvironmentVariables.TenantId;
        public static string ClientId = AzureEnvironmentVariables.ClientId;
        public static string SignUpSignInPolicy = AzureEnvironmentVariables.SignUpSignInPolicyId;
        public static string DefaultPolicy = SignUpSignInPolicy;

        public void ConfigureAuth(IAppBuilder app)
        {
            TokenValidationParameters tvps = new TokenValidationParameters
            {
                ValidAudience = ClientId,
                AuthenticationType = Startup.DefaultPolicy,
                SaveSigninToken = true,
            };

            string metadataEndpoint = String.Format(AadInstance, Tenant, DefaultPolicy);

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
            {
                AccessTokenFormat = new JwtFormat(tvps, new OpenIdConnectCachingSecurityTokenProvider(metadataEndpoint))
            });
        }
    }

    public class OpenIdConnectCachingSecurityTokenProvider : IIssuerSecurityKeyProvider
    {
        public ConfigurationManager&amp;lt;OpenIdConnectConfiguration&amp;gt; _configManager;
        private string _issuer;
        private IEnumerable&amp;lt;SecurityKey&amp;gt; _keys;
        private readonly string _metadataEndpoint;

        private readonly ReaderWriterLockSlim _synclock = new ReaderWriterLockSlim();

        public OpenIdConnectCachingSecurityTokenProvider(string metadataEndpoint)
        {
            _metadataEndpoint = metadataEndpoint;
            _configManager = new ConfigurationManager&amp;lt;OpenIdConnectConfiguration&amp;gt;(metadataEndpoint, new OpenIdConnectConfigurationRetriever());

            RetrieveMetadata();
        }


        public string Issuer
        {
            get
            {
                RetrieveMetadata();
                _synclock.EnterReadLock();
                try
                {
                    return _issuer;
                }
                finally
                {
                    _synclock.ExitReadLock();
                }
            }
        }

        public IEnumerable&amp;lt;SecurityKey&amp;gt; SecurityKeys
        {
            get
            {
                RetrieveMetadata();
                _synclock.EnterReadLock();
                try
                {
                    return _keys;
                }
                finally
                {
                    _synclock.ExitReadLock();
                }
            }
        }

        private void RetrieveMetadata()
        {
            _synclock.EnterWriteLock();
            try
            {
                OpenIdConnectConfiguration config = Task.Run(_configManager.GetConfigurationAsync).Result;
                _issuer = config.Issuer;
                _keys = config.SigningKeys;
            }
            finally
            {
                _synclock.ExitWriteLock();
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;Now go ahead and call your Startup extension method in the &lt;code&gt;Configurations&lt;/code&gt; function within your Startup.cs file to actually register your Auth Provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            HttpConfiguration config = new HttpConfiguration();
            WebApiConfig.Register(config);
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Finally, add the &lt;code&gt;Authorize&lt;/code&gt; annotation in your controllers on the Endpoints that you'd like to protect and avoid any unauthorized access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Authorize]
public class YourAwesomeApiController: ApiController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! 🎉✨ &lt;/p&gt;

&lt;p&gt;You've now unlocked the secrets of integrating Azure Active Directory B2C in your ASP.NET 4.5 WebAPI, proving once and for all that old dogs can learn some fantastic new tricks! 🐶🎩 &lt;/p&gt;

&lt;p&gt;Happy coding and may your cloud adventures be filled with endless fun and success! 🌌💖✨&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
