<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Azure Static Web Apps &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/azure-static-web-apps/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sun, 31 Mar 2024 17:15:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Entra ID (Azure AD) SSO and Azure Static Web Apps</title>
		<link>https://blog.andreev.it/2024/03/entra-id-azure-ad-sso-and-azure-static-web-apps/</link>
					<comments>https://blog.andreev.it/2024/03/entra-id-azure-ad-sso-and-azure-static-web-apps/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 31 Mar 2024 17:15:00 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Azure AD]]></category>
		<category><![CDATA[Azure Static Web Apps]]></category>
		<category><![CDATA[entra ID]]></category>
		<category><![CDATA[SSO]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=9861</guid>

					<description><![CDATA[In this post I&#8217;ll explain how to configure a static web app in Azure&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll explain how to configure a static web app in Azure and put the app behind Entra ID (Azure AD) SSO authentication. You&#8217;ll have the same protection as logging with your Entra ID credentials to Azure and Office 365. There is no need for any code change in the app. As long as you are an user or a member of an Entra ID group assigned to the Enterprise Application, then you can access the Static Web App URL. I&#8217;ll use Azure DevOps to host the files for the web site, but you can use any other repo. </p>
<h1>Azure DevOps</h1>
<p>Log to your ADO organization and create a new project. I called mine <em>Static Web App</em>. Click on <strong>Initialize </strong>and then copy the path so you can clone it locally.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-1024x836.png" alt="" width="1024" height="836" class="aligncenter size-large wp-image-9872" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-1024x836.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-300x245.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-768x627.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-1170x955.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-01-585x478.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-01.png 1357w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Once cloned, go to the repo locally and you&#8217;ll see a README.md file. Clone this web site template or just create an index.html file. </p>
<pre class="brush: bash; title: ; notranslate">
git clone https://github.com/designmodo/html-website-templates.git
</pre>
<p>Then move the index file back to the root of our repo.</p>
<pre class="brush: bash; title: ; notranslate">
mv html-website-templates/Animated\ Landing\ Page\ Website\ Template/* .
rm -rf html-website-templates/
</pre>
<p>You should have the index.html file in the root of our repo. Push to ADO.</p>
<pre class="brush: bash; title: ; notranslate">
git add .
git commit -m &quot;Updated website&quot;
git push
</pre>
<h1>Azure Static Web App</h1>
<p>Log to your Azure subscription and create or use an existing resource group. I&#8217;ll call mine <strong>rgStaticWebApp</strong>. Go to the <strong>Static Web Apps</strong> menu and create a new <strong>Static Web App</strong>. Specify a subscription, a resource group and name it. In my case it&#8217;s called <em>mystaticwebapp</em>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-02-1024x506.png" alt="" width="1024" height="506" class="aligncenter size-large wp-image-9874" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-02-1024x506.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-02-300x148.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-02-768x379.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-02-585x289.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-02.png 1156w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Make sure you choose the <strong>Standard hosting plan</strong>. SSO won&#8217;t work with the free plan. Choose the repo location, the branch and <strong>HTML </strong>for <strong>Build Preset</strong>.<br />
Use the defaults for the rest and click on <strong>Create</strong>. The static web site will be deployed in 5-10 seconds and if you go to the resource, click <strong>Overview</strong>, you&#8217;ll see the URL of your website. Go to that URL and you&#8217;ll see our website is public.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-04.jpg"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-1024x642.jpg" alt="" width="1024" height="642" class="aligncenter size-large wp-image-9875" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-1024x642.jpg 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-300x188.jpg 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-768x482.jpg 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-1536x963.jpg 1536w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-1920x1204.jpg 1920w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-1170x734.jpg 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-04-585x367.jpg 585w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Custom domain (optional)</h1>
<p>In case you want a custom domain, then these changes are required. This is not a requirement for the SSO, but it&#8217;s better if you have your own domain URL.<br />
Click on <strong>Custom Domains</strong> and then choose where is your domain hosted. In my case I have it with CloudFlare.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-05.png" alt="" width="895" height="603" class="aligncenter size-full wp-image-9876" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-05.png 895w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-05-300x202.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-05-768x517.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-05-585x394.png 585w" sizes="(max-width: 895px) 100vw, 895px" /></a><br />
Enter how you want to access your website, in my case it is <em>mysite.andreev.it</em>.<br />
You&#8217;ll have to create a CNAME in CloudFlare.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-06.png" alt="" width="838" height="501" class="aligncenter size-full wp-image-9882" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-06.png 838w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-06-300x179.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-06-768x459.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-06-585x350.png 585w" sizes="(max-width: 838px) 100vw, 838px" /></a><br />
Do not proxy it thru CloudFlare for now.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-1024x116.png" alt="" width="1024" height="116" class="aligncenter size-large wp-image-9883" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-1024x116.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-300x34.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-768x87.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-1170x133.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-07-585x66.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-07.png 1306w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Click on <strong>Add </strong>at the bottom and it might take some time for Azure to verify the new CNAME record. In my case it took less than a minute.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-08.png" alt="" width="808" height="589" class="aligncenter size-full wp-image-9884" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-08.png 808w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-08-300x219.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-08-768x560.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-08-585x426.png 585w" sizes="(max-width: 808px) 100vw, 808px" /></a><br />
&#8230;and if you go to <em>whateveryou.namedyour.site</em>, you should see the same static web page.</p>
<h1>Entra ID (Azure AD) SSO</h1>
<p>In order to add SSO, we have to add a file in the root of our static web site and then make some changes in Azure. Refer to this <a href="https://learn.microsoft.com/en-us/azure/static-web-apps/authentication-custom?tabs=aad%2Cinvitations" rel="noopener" target="_blank">link </a>for more information.<br />
Create the following file in the root of the static web site and name it <strong>staticwebapp.config.json</strong>. It has to be this name.<br />
This is what the file looks like.</p>
<pre class="brush: xml; highlight: [18,19,20]; title: ; notranslate">
{
  &quot;routes&quot;: &#x5B;
    {
      &quot;route&quot;: &quot;/*&quot;,
      &quot;allowedRoles&quot;: &#x5B;&quot;authenticated&quot;]
    }
  ],
  &quot;responseOverrides&quot;: {
    &quot;401&quot;: {
      &quot;statusCode&quot;: 302,
      &quot;redirect&quot;: &quot;/.auth/login/aad&quot;
    }
  },
  &quot;auth&quot;: {
    &quot;identityProviders&quot;: {
      &quot;azureActiveDirectory&quot;: {
        &quot;registration&quot;: {
          &quot;openIdIssuer&quot;: &quot;https://login.microsoftonline.com/TENANT_ID/v2.0&quot;,
          &quot;clientIdSettingName&quot;: &quot;AZURE_CLIENT_ID&quot;,
          &quot;clientSecretSettingName&quot;: &quot;AZURE_CLIENT_SECRET&quot;
        }
      }
    }
  }
}
</pre>
<p>We need 3 values. The first value, <strong>TENANT_ID</strong> needs to go to this file hardcoded and the other two values for the <strong>CLIENT_ID</strong> and <strong>CLIENT_SECRET</strong> will be added in Azure. Here is how to fine these values. Go to Entra ID and click <strong>Overview</strong>. This is your <strong>TENANT_ID</strong> value. Copy and paste that value in line 18 and save the file. After, <em>git add/commit/push</em> the file back to Azure DevOps repo.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-09.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-1024x572.png" alt="" width="1024" height="572" class="aligncenter size-large wp-image-9890" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-1024x572.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-300x168.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-768x429.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-1170x654.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-09-585x327.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-09.png 1204w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Go to <strong>App Registrations</strong> and click on <strong>New registration</strong>.<br />
Enter these values and click <strong>Register</strong>. Replace the URL with yours even if it&#8217;s not a custom domain. Add <strong>.auth/login/aad/callback</strong> as a suffix.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-10.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-10-802x1024.png" alt="" width="802" height="1024" class="aligncenter size-large wp-image-9896" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-10-802x1024.png 802w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-10-235x300.png 235w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-10-768x980.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-10-585x747.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-10.png 1035w" sizes="(max-width: 802px) 100vw, 802px" /></a><br />
The app registers right away and if you click the <strong>Overview </strong>you&#8217;ll see the app client ID. Copy this value in notepad or somewhere.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-12.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-1024x488.png" alt="" width="1024" height="488" class="aligncenter size-large wp-image-9891" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-1024x488.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-300x143.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-768x366.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-1170x557.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-12-585x279.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-12.png 1279w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
From the menu on the left, click <strong>Certificates &#038; secrets</strong> and then click on <strong>New client secret</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-13.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-13-1024x611.png" alt="" width="1024" height="611" class="aligncenter size-large wp-image-9892" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-13-1024x611.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-13-300x179.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-13-768x458.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-13-585x349.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-13.png 1027w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Name the secret and choose for how long it&#8217;s valid.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-14.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-14.png" alt="" width="841" height="253" class="aligncenter size-full wp-image-9893" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-14.png 841w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-14-300x90.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-14-768x231.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-14-585x176.png 585w" sizes="(max-width: 841px) 100vw, 841px" /></a><br />
You&#8217;ll see that a secret has been created and you&#8217;ll have a value and a secret ID. Copy the value not the ID in notepad or somewhere.<br />
Now, go to the Static Web App and click on Environment variables. Add both <strong>AZURE_CLIENT_ID</strong> and <strong>AZURE_CLIENT_SECRET</strong> and click <strong>Apply </strong>at the bottom.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-15.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-1024x537.png" alt="" width="1024" height="537" class="aligncenter size-large wp-image-9894" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-1024x537.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-300x157.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-768x403.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-1170x614.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-15-585x307.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-15.png 1246w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Finally, go to <strong>App Registration</strong>, find your app there, click <strong>Authentication </strong>on the left and make sure that <strong>ID tokens</strong> option is checked.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-11.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-1024x739.png" alt="" width="1024" height="739" class="aligncenter size-large wp-image-9898" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-1024x739.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-300x216.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-768x554.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-1536x1108.png 1536w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-1170x844.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11-585x422.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-11.png 1561w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Now, if you go to the URL of the app, you&#8217;ll be prompted to log in and after successfully logging in, you&#8217;ll see our static web page. But every user from your tenant can log in, the only restriction is that you are member of the Entra ID tenant. If you want to restrict the website only to specific people, do the following. Go to <strong>Enterprise Applications</strong>, find your application and click on <strong>Properties</strong>. Make sure <strong>Assignment required</strong> is set to <strong>Yes</strong>. Click <strong>Save </strong>on top.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/03/P172-16.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-1024x602.png" alt="" width="1024" height="602" class="aligncenter size-large wp-image-9899" srcset="https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-1024x602.png 1024w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-300x176.png 300w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-768x451.png 768w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-1536x902.png 1536w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-1170x687.png 1170w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16-585x344.png 585w, https://blog.andreev.it/wp-content/uploads/2024/03/P172-16.png 1590w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
Then, click on <strong>Users and Groups</strong> and assign a group or users to the app. Mind that if you use the free version of Entra ID, you won&#8217;t be able to assign groups, only users.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2024/03/entra-id-azure-ad-sso-and-azure-static-web-apps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
