How to automate the connection to a SharePoint site with multi factor automation for Azure Development Pipiline

Mikhail 41 Reputation points

We are trying to organize an Azure Development Pipeline where the deployment and some development process would be automated.

The SharePoint sites we are currently working with require a multi-factor authentication, which mean the site access requires confirmation from either the phone up or the security code

Previously in the code the following connection logic used to work

 context.Credentials = new SharePointOnlineCredentials(  

This code no longer works as this code cannot connect to the multi factor authentication sites and a different code is used to connect

var authManager = new OfficeDevPnP.Core.AuthenticationManager();  
context = authManager.GetWebLoginClientContext(ConfigSettings.SiteUrl)  

This code works well when the code is run manually. When this code is reached, the connection interface opens and the credentials are handled and confirmed.

But are the ways to automate the authentication process? Can the multi-factor authentication be fully automated using some sort of secure token?

Thank you in advance for your answers

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,219 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,207 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. FrankHu-MSFT 976 Reputation points


    The multi factor authentication cannot be automated, as a large point of the multi factor is to provide secure authentication from a human that is logging in with multiple points of security from said human to prove their identity.

    Perhaps you could utilize a different authentication protocol, such as providing the sharepoint server a service principal that has exclusive access to your azure development pipeline.
    If your azure dev pipeline is utilizing AAD OAuth2 you would be able to utilize the AAD Client Credential flow.

    Note per the post below, for further help on this azure devops pipeline authentication question please open a developer community item with the tag [AltCreds] in the title. For faster service, please search for [AltCreds] in the developer community forum first, as your question might already be answered. You can reach out to us on Twitter at @Azure Dev Ops too.

    Reference Links :

    Please remember to mark one of the responses as answer if your question has been answered. If not please let us know if there are anymore questions.

    0 comments No comments

  2. ocean specialists 1 Reputation point

    Thanks for such a precious Knowledge.

    Please Visit:


    0 comments No comments