<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Azure]]></title><description><![CDATA[Azure]]></description><link>https://measifalam-azure.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 26 Jun 2026 19:24:57 GMT</lastBuildDate><atom:link href="https://measifalam-azure.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Azure AD]]></title><description><![CDATA[Azure AD Web API Authentication (Concepts)

🎯 Objective
Understand how Azure AD authentication works between a UI application and a backend Web API.

🧠 Core Architecture
A typical web system has two]]></description><link>https://measifalam-azure.hashnode.dev/azure-ad</link><guid isPermaLink="true">https://measifalam-azure.hashnode.dev/azure-ad</guid><dc:creator><![CDATA[Md Asif Alam]]></dc:creator><pubDate>Fri, 06 Mar 2026 05:46:33 GMT</pubDate><content:encoded><![CDATA[<h1>Azure AD Web API Authentication (Concepts)</h1>
<hr />
<h2>🎯 Objective</h2>
<p>Understand how <strong>Azure AD authentication works between a UI application and a backend Web API</strong>.</p>
<hr />
<h2>🧠 Core Architecture</h2>
<p>A typical web system has <strong>two logical applications</strong>:</p>
<table>
<thead>
<tr>
<th>Component</th>
<th>Role</th>
</tr>
</thead>
<tbody><tr>
<td>Frontend (UI App)</td>
<td>React / Angular / Web UI</td>
</tr>
<tr>
<td>Backend (API App)</td>
<td><a href="http://ASP.NET">ASP.NET</a> Core Web API</td>
</tr>
</tbody></table>
<p>Important concept:</p>
<ul>
<li><p>Users <strong>never call APIs directly</strong></p>
</li>
<li><p>Users interact with the <strong>UI</strong></p>
</li>
<li><p>UI calls APIs <strong>on behalf of the user</strong></p>
</li>
</ul>
<hr />
<h2>🔐 Authentication Flow</h2>
<ol>
<li><p>User opens the website.</p>
</li>
<li><p>Website redirects the user to <strong>Microsoft Entra ID</strong> (Azure AD) login.</p>
</li>
<li><p>User enters credentials.</p>
</li>
<li><p>Azure AD authenticates the user.</p>
</li>
<li><p>Azure AD returns a <strong>token</strong> to the UI app.</p>
</li>
<li><p>UI sends that token when calling the API.</p>
</li>
<li><p>API validates the token before responding.</p>
</li>
</ol>
<hr />
<h2>🏢 Tenant Concept</h2>
<p>A <strong>Tenant</strong> represents an organization.</p>
<p>Example:</p>
<pre><code class="language-plaintext">Tenant
 ├── Users
 │   ├── Neil
 │   └── Steve
 │
 └── Applications
     ├── UI App
     └── Backend API
</code></pre>
<p>Key points:</p>
<ul>
<li><p>Users exist <strong>at tenant level</strong></p>
</li>
<li><p>Applications also exist <strong>inside tenant</strong></p>
</li>
</ul>
<hr />
<h2>🧾 App Registrations</h2>
<p>Two app registrations are required.</p>
<table>
<thead>
<tr>
<th>App</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td>UI App</td>
<td>Frontend application</td>
</tr>
<tr>
<td>Backend App</td>
<td>Web API</td>
</tr>
</tbody></table>
<hr />
<h2>📡 Exposing APIs</h2>
<p>Backend App → <strong>Expose an API</strong></p>
<p>This allows other apps to call it.</p>
<p>Example scope:</p>
<pre><code class="language-plaintext">scope.any
</code></pre>
<hr />
<h2>✅ Conditions for API Call</h2>
<p>For a successful API call:</p>
<p>1️⃣ User must be authenticated</p>
<p>2️⃣ UI App must have permission to call API</p>
<hr />
<h1>Creating <a href="http://ASP.NET">ASP.NET</a> Core Web API with Azure AD</h1>
<h2>🎯 Objective</h2>
<p>Create a <strong>Web API project with Azure AD authentication enabled</strong>.</p>
<hr />
<h2>🛠 Creating the Project</h2>
<p>In <strong>Microsoft Visual Studio</strong>:</p>
<ol>
<li><p>Create New Project</p>
</li>
<li><p>Select <a href="http://ASP.NET"><strong>ASP.NET</strong></a> <strong>Core Web API</strong></p>
</li>
<li><p>Project name:</p>
</li>
</ol>
<pre><code class="language-plaintext">DemoApiAuthenticationUsingAzureAD
</code></pre>
<ol>
<li><p>Uncheck HTTPS (for demo)</p>
</li>
<li><p>Authentication Type:</p>
</li>
</ol>
<pre><code class="language-plaintext">Microsoft Identity Platform
</code></pre>
<p>This automatically configures Azure AD support.</p>
<hr />
<h2>📂 Important Files</h2>
<h3>Controller</h3>
<pre><code class="language-plaintext">[Authorize]
public class WeatherForecastController : ControllerBase
{
}
</code></pre>
<p>Meaning:</p>
<ul>
<li>All endpoints require authentication.</li>
</ul>
<hr />
<h3>Program.cs</h3>
<pre><code class="language-plaintext">builder.Services
    .AddAuthentication()
    .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));
</code></pre>
<p>This configures Azure AD authentication.</p>
<hr />
<h3>appsettings.json</h3>
<pre><code class="language-plaintext">"AzureAd": {
  "TenantId": "",
  "ClientId": "",
  "Scopes": ""
}
</code></pre>
<p>These values come from Azure Portal.</p>
<hr />
<h2>⚠️ First Run Result</h2>
<p>API returns:</p>
<pre><code class="language-plaintext">401 Unauthorized
</code></pre>
<p>Because Azure AD is not configured yet.</p>
<hr />
<h2>🔧 Temporary Fix</h2>
<p>Disable authentication for testing:</p>
<pre><code class="language-plaintext">[AllowAnonymous]
</code></pre>
<p>Now API works.</p>
<hr />
<h2>Testing in Postman</h2>
<p>Endpoint example:</p>
<pre><code class="language-plaintext">GET /weather/getWeatherData
</code></pre>
<p>Result:</p>
<pre><code class="language-plaintext">200 OK
</code></pre>
<hr />
<h1>Implementing Azure AD Authentication</h1>
<h2>🎯 Objective</h2>
<p>Configure Azure AD authentication for Web API.</p>
<hr />
<h1>Step 1 — Backend App Registration</h1>
<p>In <strong>Microsoft Azure Portal</strong></p>
<p>Navigate:</p>
<pre><code class="language-plaintext">Microsoft Entra ID
 → App Registrations
 → New Registration
</code></pre>
<p>Create:</p>
<pre><code class="language-plaintext">My Backend App
</code></pre>
<hr />
<h2>Expose API</h2>
<p>Open:</p>
<pre><code class="language-plaintext">Expose an API
</code></pre>
<p>Add:</p>
<pre><code class="language-plaintext">Application ID URI
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">api://backend-api-id
</code></pre>
<hr />
<h2>Create Scope</h2>
<p>Example:</p>
<pre><code class="language-plaintext">scope.any
</code></pre>
<p>Purpose:</p>
<p>Defines <strong>permission to access API</strong>.</p>
<hr />
<h1>Step 2 — Frontend App Registration</h1>
<p>Create another app:</p>
<pre><code class="language-plaintext">My UI App
</code></pre>
<p>Platform:</p>
<pre><code class="language-plaintext">Single Page Application
</code></pre>
<p>Add Redirect URI (Postman / frontend).</p>
<hr />
<h2>Add API Permissions</h2>
<p>Navigate:</p>
<pre><code class="language-plaintext">API Permissions
 → Add Permission
 → My APIs
</code></pre>
<p>Select:</p>
<pre><code class="language-plaintext">My Backend App
</code></pre>
<p>Add permission:</p>
<pre><code class="language-plaintext">scope.any
</code></pre>
<hr />
<h2>Enable Tokens</h2>
<p>Under Authentication enable:</p>
<pre><code class="language-plaintext">Access Tokens
ID Tokens
</code></pre>
<hr />
<h1>Step 3 — Configure Web API</h1>
<p>In <strong>appsettings.json</strong></p>
<pre><code class="language-plaintext">"AzureAd": {
 "TenantId": "your-tenant-id",
 "ClientId": "backend-app-client-id",
 "Scopes": "scope.any"
}
</code></pre>
<p>Important:</p>
<p>Use <strong>Backend App ClientId</strong>, not UI app.</p>
<hr />
<h1>Service to Service Authentication (S2S)</h1>
<h2>🎯 Objective</h2>
<p>Allow <strong>one service to call another service securely</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">HRApp → FinanceApp API
</code></pre>
<hr />
<h1>Backend API</h1>
<pre><code class="language-plaintext">FinanceApp
</code></pre>
<p>Example endpoint:</p>
<pre><code class="language-plaintext">/financeapp/getbunetprofit
</code></pre>
<p>Controller:</p>
<pre><code class="language-plaintext">[Authorize]
[Route("financeapp/getbunetprofit")]
public string GetProfit()
{
 return "Net profit of BU is 1.4 million";
}
</code></pre>
<hr />
<h1>App Roles for S2S Authentication</h1>
<h2>Create App Role</h2>
<p>In FinanceApp:</p>
<pre><code class="language-plaintext">App roles
 → Create role
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">appro.read
</code></pre>
<p>Allowed member type:</p>
<pre><code class="language-plaintext">Application
</code></pre>
<p>Meaning:</p>
<p>Only <strong>apps</strong>, not users.</p>
<hr />
<h1>HRApp Permissions</h1>
<p>In HRApp:</p>
<pre><code class="language-plaintext">API Permissions
 → Add Permission
 → FinanceApp
 → appro.read
</code></pre>
<p>Grant Admin Consent.</p>
<hr />
<h1>Protect API with Role</h1>
<p>Controller:</p>
<pre><code class="language-plaintext">[Authorize(Roles="appro.read")]
</code></pre>
<p>Only apps with this role can access.</p>
<hr />
<h1>Generating JWT Token (Client Credentials)</h1>
<h2>🎯 Objective</h2>
<p>Generate <strong>JWT token for service-to-service API calls</strong>.</p>
<hr />
<h2>Required Fields</h2>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>Client ID</td>
<td>HRApp client ID</td>
</tr>
<tr>
<td>Client Secret</td>
<td>HRApp secret</td>
</tr>
<tr>
<td>Resource</td>
<td>FinanceApp API</td>
</tr>
<tr>
<td>Grant Type</td>
<td>client_credentials</td>
</tr>
</tbody></table>
<hr />
<h2>Flow</h2>
<pre><code class="language-plaintext">HRApp → Azure AD → JWT Token → FinanceApp API
</code></pre>
<p>Steps:</p>
<ol>
<li><p>HRApp requests token.</p>
</li>
<li><p>Azure AD validates credentials.</p>
</li>
<li><p>Azure AD issues JWT token.</p>
</li>
<li><p>HRApp sends token to FinanceApp API.</p>
</li>
</ol>
<hr />
<h1>Calling API from Postman</h1>
<h2>Step 1 — Verify API Requires Token</h2>
<p>Request:</p>
<pre><code class="language-plaintext">GET /financeapp/getbunetprofit
</code></pre>
<p>Response:</p>
<pre><code class="language-plaintext">401 Unauthorized
</code></pre>
<hr />
<h1>Step 2 — Configure OAuth2</h1>
<p>In <strong>Postman</strong></p>
<p>Authorization type:</p>
<pre><code class="language-plaintext">OAuth 2.0
</code></pre>
<p>Grant Type:</p>
<pre><code class="language-plaintext">Client Credentials
</code></pre>
<p>Required values:</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>Token URL</td>
<td>Azure AD token endpoint</td>
</tr>
<tr>
<td>Client ID</td>
<td>HRApp</td>
</tr>
<tr>
<td>Client Secret</td>
<td>HRApp secret</td>
</tr>
<tr>
<td>Resource</td>
<td>FinanceApp API</td>
</tr>
</tbody></table>
<hr />
<h1>Step 3 — Call API</h1>
<p>Add token as:</p>
<pre><code class="language-plaintext">Authorization: Bearer &lt;token&gt;
</code></pre>
<p>Response:</p>
<pre><code class="language-plaintext">200 OK
</code></pre>
<hr />
<h1>Understanding Tenant and App Registration</h1>
<h2>What is a Tenant</h2>
<p>A tenant represents <strong>an organization in Azure</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">Tenant: ABC Technologies
</code></pre>
<p>Inside tenant:</p>
<pre><code class="language-plaintext">Users
Applications
Permissions
Policies
</code></pre>
<hr />
<h2>Users in Tenant</h2>
<p>Examples:</p>
<pre><code class="language-plaintext">neil.david@abcd.com
mark.phillips@abcd.com
</code></pre>
<p>You can also add <strong>guest users</strong>.</p>
<hr />
<h1>App Registration Purpose</h1>
<p>App registration allows <strong>applications to interact with Azure AD</strong>.</p>
<p>Example use cases:</p>
<ul>
<li><p>Authentication</p>
</li>
<li><p>Access APIs</p>
</li>
<li><p>Read tenant users</p>
</li>
</ul>
<hr />
<h2>Important Credentials</h2>
<p>App registration generates:</p>
<pre><code class="language-plaintext">Client ID
Client Secret
</code></pre>
<p>These are used by applications to authenticate with Azure AD.</p>
<hr />
]]></content:encoded></item></channel></rss>