Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.

2021-07-26T16:10:33.107+00:00

When we are deploying the web app we are facing this issue:

Error: Failed to get resource ID for resource type 'Microsoft.Web/Sites' and resource name 'DPSREQUESTFORMS'. Error: Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired. For more information refer https://aka.ms/azureappservicedeploytsg

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Venu Kotte 96 Reputation points
    2022-02-18T12:45:57.017+00:00

    Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.

    if you are facing this issue , you can navigate to

    Azure Devops _____> ProjectSettings ------> PipeLines --------> Service Connections --------->

    here you can find the list of service connections available were displayed . select the service connection which you are facing issue

    175882-image.png

    you will find this screen

    175789-image.png

    it will navigate to expired page

    175809-image.png

    then you can observe expired token one , delete that and create a new certificate .

    final step is you need to go to back like

    Azure Devops _____> ProjectSettings ------> PipeLines --------> Service Connections --------->

    select the service connection which you are facing issue ---> select the edit button ---and just click on save button _---------> it will asks azure authentication ------> once you are done with
    successful authentication , release pipe line works like as usual ,.

    19 people found this answer helpful.

  2. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2021-07-27T15:03:48.17+00:00

    Thanks for asking question! To elaborate on this you may want to know that Azure App Service Deploy task uses the service principal in the service connection to authenticate with Azure. The task fails with this error if the service principal has expired or doesn't have permissions to the App Service.

    Recommend you to verify the validity of the service principal used and if it's present in the app registration.

    You may refer to Use role-based access control to manage access to your Azure subscription resources and SO link here

    Also check this blog on Automating Azure Resource Group deployment using a Service Principal in Visual Studio Online: Build/Release Management

    Let us know if further query on this or issue remains.

    5 people found this answer helpful.
    0 comments No comments

  3. Lance 301 Reputation points MVP Volunteer Moderator
    2023-06-07T15:07:37.7866667+00:00

    If you are here because of a YAML AzureDevops Pipeline failure, this happens because the authentication with GitHub has expired. You cannot create a new token because you cannot edit the expire done.

    Instead, the fix is really easy and is a two-click operation.

    1. Go to your pipeline's settings page
    2. Under "get sources" select the connection to GitHub.
    3. You'll see a "Authorized with service connection" setting. Just drop down that caret and select "create new connection.

    See my screenshot User's image

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.