Authenticate to SharePoint Online wit integrated security

Eliasen, Jan 46 Reputation points
2021-01-13T22:51:32.903+00:00

Hi all

I have written some code that will run as a service under a specific service account.

The code must access SharePoint Online and retrieve values from a list.

I can get it to work using credentials like this:
context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(userName, securePassword);

and I can get it to work using clientID/secret like this:
var clientContext = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(urlProd, clientId, clientSecret)

But I am not really happy with that, because both solutions require me to either hard code username/password or clientID/secret - or to have them in some configuration file and read them at runtime.

I would much rather be able to simply access SharePoint using integrated security and ust use the account under which the code is running. Is this at all possible?

Thanks.

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} vote

Accepted answer
  1. trevorseward 11,711 Reputation points
    2021-01-14T02:12:55.997+00:00

    Since SPO is using OAuth and not WIA, no.

    However, you should be securing your secrets with something like Azure KeyVault. Publish your application (i.e. using Azure Automation or an Azure App Service). The Automation/App Service uses a Managed Identity to retrieve secrets from the KeyVault. This way you're not hardcoding anything but the KeyVault URL.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-01-14T05:48:34.337+00:00

    No, SharePoint Online authenticate users this way through your own Identity Provider (IdP) or the default Azure Active Directory (Azure AD) IdP.
    Documents for your reference:
    SharePoint authentication
    Authentication options for custom application when accessing data from O365


    If the response 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.

    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.