programmatic use of Sharepoint api and 2factor authentication

Les Stockton 1 Reputation point
2021-09-09T17:19:02.07+00:00

I have need to write an application that utilizes the Sharepoint api to retrieve data from a list on the sharepoint site.
I've done this before, but in my current environment, the Sharepoint site requires a login with 2factor authentication.
I don't see how I can do this in an automated fashion in my program. The program is meant to run as a scheduled task once a day, and will not have any operator interaction.

So how does a person utilize the sharepoint api in an environment that has 2 factor authentication?

My program will be written in C#.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,239 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,573 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2021-09-09T18:20:34.367+00:00

    generally you would create a service account, that does not have interactive login permission. this account also would not have 2 factor authentication.

    0 comments No comments

  2. P a u l 10,406 Reputation points
    2021-09-09T18:28:41.787+00:00

    This article explains how to setup "App Only" to achieve this. The process is slightly different depending on whether you're using SharepointOnline/Azure or whether you're using an on-premise Sharepoint server:
    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly

    0 comments No comments

  3. RaytheonXie_MSFT 31,071 Reputation points Microsoft Vendor
    2021-09-10T02:00:23.683+00:00

    Hi @Les Stockton ,
    We can set up an app-only principal with tenant permissions to achieve this.Please refer to following steps
    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.