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#.

Microsoft 365 and Office SharePoint Server Development
Developer technologies C#
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    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,761 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 40,471 Reputation points Microsoft External Staff
    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.


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.