azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Easy Auth enabled on Azure portal for function app not allowed to exposed Swagger endpoints

Open aifazk opened this issue 1 year ago • 1 comments

Describe the issue We are using azure-functions-openapi-extension version 1.5.1 for our existing azure function app built with netcoreapp3.1, its working locally fine but when deployed to azure portal and try to access ttps://[somefunctionapp].azurewebsites.net/api/swagger/ui? returning 401 or "You do not have permission to view this directory or page." However azure function define AllowAnonymous Access in code but using the Latest version of Easy Auth at Azure portal. Please suggest any workaround or fix?

To Reproduce Steps to reproduce the behavior:

  1. Deploy Azure function to azure portal with Easy Auth enabled
  2. expose url https://[somefunctionapp].azurewebsites.net/api/swagger/ui
  3. See error

Expected behavior It should render Swagger UI page as working on locally(localhost)

Environment (please complete the following information, if applicable):

  • OS: Windows
  • Browser edge, chrome, firefox, safari

Additional context Add any other context about the problem here.

aifazk avatar Feb 08 '24 19:02 aifazk

I've got this working by excluding the following paths from EasyAuth:

  • /swagger.json
  • /openapi/
  • /swagger/ui

This can be configured using either Bicep:

resource functionAppService 'Microsoft.Web/sites@2023-12-01' existing = {
  name: 'myFunction'
}

resource functionAppConfig 'Microsoft.Web/sites/config@2023-12-01' = {
  parent: functionAppService
  name: 'authsettingsV2'
  properties: {
    platform: {
      enabled: true
    }
    globalValidation: {
      requireAuthentication: true
      unauthenticatedClientAction: 'RedirectToLoginPage'
      redirectToProvider: 'azureactivedirectory'
      excludedPaths:  [
          '/swagger.json'
          '/openapi/'
          '/swagger/ui'
        ]
    }
// omitting the rest for brevity...

or File-based configuration in Azure App Service authentication.

acatuttle avatar Mar 01 '25 14:03 acatuttle