|
1 | | -# azure-easyauth-sample |
2 | | -This provides a sample code for the EasyAuth feature on Azure App Service, Azure Static Web App and Azure Container Apps |
| 1 | +# Azure EasyAuth Sample |
| 2 | + |
| 3 | +This provides sample [Blazor](https://learn.microsoft.com/aspnet/core/blazor/) apps for the EasyAuth feature on Azure App Service, Azure Container Apps and Azure Static Web App. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [.NET 9+ SDK](https://dotnet.microsoft.com/download/dotnet/9.0) |
| 8 | +- [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) or [Visual Studio Code](https://code.visualstudio.com/) with [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) |
| 9 | +- [GitHub CLI](https://github.com/cli/cli#installation) |
| 10 | +- [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) |
| 11 | +- [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd) |
| 12 | +- [SWA CLI](https://learn.microsoft.com/azure/static-web-apps/static-web-apps-cli-install) |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +1. Clone this repository. |
| 17 | + |
| 18 | + ```bash |
| 19 | + gh repo fork devkimchi/azure-easyauth-sample --clone |
| 20 | + ``` |
| 21 | + |
| 22 | +1. Change the directory to the repository. |
| 23 | + |
| 24 | + ```bash |
| 25 | + cd azure-easyauth-sample |
| 26 | + ``` |
| 27 | + |
| 28 | +1. Build the sample apps. |
| 29 | + |
| 30 | + ```bash |
| 31 | + dotnet restore && dotnet build |
| 32 | + ``` |
| 33 | + |
| 34 | +1. Create artifacts for each app |
| 35 | + |
| 36 | + ```bash |
| 37 | + dotnet publish -c Release |
| 38 | + ``` |
| 39 | + |
| 40 | +1. Login to Azure. |
| 41 | + |
| 42 | + ```bash |
| 43 | + # Login to Azure with Azure Developer CLI |
| 44 | + azd auth login |
| 45 | + |
| 46 | + # Login to Azure with Azure CLI |
| 47 | + az login |
| 48 | + ``` |
| 49 | + |
| 50 | +1. Run the following command to provision and deploy the Azure resources. |
| 51 | + |
| 52 | + ```bash |
| 53 | + azd up |
| 54 | + ``` |
| 55 | + |
| 56 | + It will ask you to provide the following parameters: |
| 57 | + |
| 58 | + - New environment name |
| 59 | + - Azure subscription to use |
| 60 | + - Azure location to provision resources |
| 61 | + - `sttappLocation` to provision Azure Static Web App |
| 62 | + |
| 63 | + It provisions Azure Container Apps, Azure App Service, and Azure Static Web App instances and deploys the sample apps to each of them. |
| 64 | + |
| 65 | +1. Get each app's URL. |
| 66 | +
|
| 67 | + ```bash |
| 68 | + # Web App URL |
| 69 | + azd env get-value AZURE_RESOURCE_EASYAUTH_WEBAPP_URL |
| 70 | +
|
| 71 | + # Container App URL |
| 72 | + azd env get-value AZURE_RESOURCE_EASYAUTH_CONTAINERAPP_URL |
| 73 | +
|
| 74 | + # Static Web App URL |
| 75 | + azd env get-value AZURE_RESOURCE_EASYAUTH_STATICAPP_URL |
| 76 | + ``` |
| 77 | +
|
| 78 | +1. 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. |
| 79 | + |
| 80 | +## Known Limitations of Azure EasyAuth |
| 81 | + |
| 82 | +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 the authentication/authorisation logic by yourself. |
| 83 | + |
| 84 | +## Clean Up |
| 85 | + |
| 86 | +If you want to clean up the resources provisioned by the `azd up` command, run the following command: |
| 87 | + |
| 88 | +```bash |
| 89 | +azd down --force --purge |
| 90 | +``` |
| 91 | + |
| 92 | +## Additional Resources |
| 93 | + |
| 94 | +- [Azure EasyAuth](https://learn.microsoft.com/azure/app-service/scenario-secure-app-authentication-app-service?tabs=workforce-configuration) |
| 95 | +- [Azure App Service](https://learn.microsoft.com/azure/app-service/overview) |
| 96 | +- [Azure Container Apps](https://learn.microsoft.com/azure/container-apps/overview) |
| 97 | +- [Azure Static Web Apps](https://learn.microsoft.com/azure/static-web-apps/overview) |
0 commit comments