This provides sample Blazor apps for the EasyAuth feature on Azure App Service, Azure Container Apps and Azure Static Web App.
- .NET 9+ SDK
- Visual Studio 2022 or Visual Studio Code with C# Dev Kit
- GitHub CLI
- Azure CLI
- Azure Developer CLI
- SWA CLI
-
Clone this repository.
gh repo fork devkimchi/azure-easyauth-sample --clone
-
Change the directory to the repository.
cd azure-easyauth-sample
-
Build the sample apps.
dotnet restore && dotnet build
-
Login to Azure.
# Login to Azure with Azure Developer CLI azd auth login # Login to Azure with Azure CLI az login
-
Run the following command to provision and deploy the Azure resources.
azd up
It will ask you to provide the following parameters:
- New environment name
- Azure subscription to use
- Azure location to provision resources
sttappLocation
to provision Azure Static Web App
It provisions Azure Container Apps, Azure App Service, and Azure Static Web App instances and deploys the sample apps to each of them.
-
Get each app's URL.
# Web App URL azd env get-value AZURE_RESOURCE_EASYAUTH_WEBAPP_URL # Container App URL azd env get-value AZURE_RESOURCE_EASYAUTH_CONTAINERAPP_URL # Static Web App URL azd env get-value AZURE_RESOURCE_EASYAUTH_STATICAPP_URL
-
With the URLs above, navigate each app with your browser. You'll be redirected to login your apps with Entra ID first. Once you logged in, you'll see the logged-in user's information.
Azure EasyAuth is supposed to protect your entire app, not for specific pages. Therefore, if you want to protect certain pages of your app, you have to implement a custom authentication/authorisation logic by yourself. In this sample app, the EasyAuth.Handlers
project is the one.
If you want to clean up the resources provisioned by the azd up
command, run the following command:
azd down --force --purge