question

LesStockton-0117 avatar image
0 Votes"
LesStockton-0117 asked RaytheonXie-MSFT commented

programmatic use of Sharepoint api and 2factor authentication

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

dotnet-csharpoffice-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Paul-5034 avatar image
0 Votes"
Paul-5034 answered

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://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @LesStockton-0117 ,
We can set up an app-only principal with tenant permissions to achieve this.Please refer to following steps
https://docs.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.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

now I just need to find a DotNet Core C# example of how to connect using this app-only tenant.

0 Votes 0 ·

I need to figure out how to authenticate in c#, accessing a on premise Sharepoint instance.
and utilizing DotNet Core.

0 Votes 0 ·

Hi @LesStockton-0117 ,
You can refer to following link:
https://www.c-sharpcorner.com/article/connect-to-sharepoint-online-site-with-app-only-authentication/

Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

0 Votes 0 ·