/azure-easyauth-sample

This provides a sample code for the EasyAuth feature on Azure App Service, Azure Static Web App and Azure Container Apps

Primary LanguageCSSMIT LicenseMIT

Azure EasyAuth Sample

This provides sample Blazor apps for the EasyAuth feature on Azure App Service, Azure Container Apps and Azure Static Web App.

Prerequisites

Getting Started

  1. Clone this repository.

    gh repo fork devkimchi/azure-easyauth-sample --clone
  2. Change the directory to the repository.

    cd azure-easyauth-sample
  3. Build the sample apps.

    dotnet restore && dotnet build
  4. Login to Azure.

    # Login to Azure with Azure Developer CLI
    azd auth login
    
    # Login to Azure with Azure CLI
    az login
  5. 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.

  6. 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
  7. 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.

Known Limitations of Azure EasyAuth

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.

Clean Up

If you want to clean up the resources provisioned by the azd up command, run the following command:

azd down --force --purge

Additional Resources