how to solve azure web app deployment Unauthorized (CODE: 401)
Asked Answered
C

3

6

Hi I'm trying to deploy my react app using Azure Web app service using github action as deployment provider. build process have done but deploy step shows error at the end. here is error sample:

Run azure/webapps-deploy@v2
  with:
    app-name: productlister
    slot-name: Production
    publish-profile: ***
    package: .
Package deployment using ZIP Deploy initiated.
Error: Failed to deploy web package to App Service.
Error: Deployment Failed, Error: Failed to deploy web package to App Service.
Unauthorized (CODE: 401)
App Service Application URL: [https://productlister.azurewebsites.net](https://productlister.azurewebsites.net)

i used github action yml file as workflow. i looking for solution of this error. im not aware about error.

Cormick answered 7/6, 2023 at 2:31 Comment(4)
401 unauthorized is likely to mean your publish-profile credentials are wrong. Try recreating it. see : learn.microsoft.com/en-us/azure/app-service/…Gardant
i follow instruction but it gives an another error.Cormick
i just did and app is deployed but when i visit https://productlister.azurewebsites.net/ it shows an message You do not have permission to view this directory or page.Cormick
Check the networking tab in your azure app service and ensure it is open to the internet (that there are no network access restrictions rules defined to disable public access) learn.microsoft.com/en-us/azure/app-service/…Gardant
C
3

I created one sample React app and pushed it to Github like below:-

enter image description here

enter image description here

I created one Azure Web app with Node version 18 and added these 2 Settings in Configuration, Refer below:-

enter image description here

Settings:-

SCM_DO_BUILD_DURING_DEPLOYMENT true

WEBSITE_WEBDEPLOY_USE_SCM true

went to Deployment > Deployment Center on left tab and selected above github repository and initiated the Github action workflow for Deployment like below:-

enter image description here

My github workflow:-

You can find my complete github workflow in this Link.

Code Reference


name: Build and deploy Node.js app to Azure Web App - siliconwebapp

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: '18.x'

      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm run test --if-present
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: node-app
          path: .

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: node-app

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'siliconwebapp'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_AB22E951505E4DC799565C7665CCC5D8 }}
          package: .
          

Output:-

enter image description here

enter image description here

enter image description here

Note- Apart from adding the above Settings, When I deployed the App in different Web app even I received the same error code as yours, Refer below:-

Another Web app with name silicon-webapp where as the earlier one which was successful named siliconwebapp.

enter image description here

enter image description here

Package deployment using ZIP Deploy initiated.

[8](https://github.com/xxx/my-app1/actions/runs/xxx/jobs/xxx#step:3:9)Error: Failed to deploy web package to App Service.

[9](https://github.com/xxx/my-app1/actions/runs/xxx06070/jobs/xxx53864#step:3:10)Error: Deployment Failed, Error: Failed to deploy web package to App Service.

[10](https://github.com/xxxdesai/my-app1/actions/runs/xxx306070/jobs/9xxxx#step:3:11)Unauthorized (CODE: 401)

I deployed a new Web app siliconwebapp in another region and then added the above settings in Configuration and initiated the Github workflow from Deployment Center which was successful.

Reference:-

github - unable to deploy to azure web app services - Stack Overflow

Citrus answered 7/6, 2023 at 9:15 Comment(0)
V
3

I had the same problem and i found a good way to analyze the problem:

If you navigate to your "Deployment Center" in Azure, you could download the publish profile. This could help you to check what went wrong. (You could also just import the publish profiles, this should definitely work.) Manage publish profile > Download publish profile

Vestiary answered 27/9, 2023 at 13:10 Comment(0)
C
3

For me the solution was to enable Basic Auth found at

Your App Service > Configuration (on left pane) > SCM Basic Auth > On

Showing SCM Enabling option

Chromatic answered 14/6 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.