Forum Discussion

John_Wil740's avatar
John_Wil740
Copper Contributor
Jun 05, 2023

SharePoint Authentication

Hi,

 

I have a solution, in which I add an item to a SharePoint 2019 on-premise list. I am not passing credentails, thus the connection is setup using the credentails of the user running the app.

 

On my machine this works great, however on another user's machine, not the credentials of the user running the app are used, but the credentials of the user which is used to setup SharePoint on the machine are used. That account is the "modified by" instead of the account running the App.

 

The difference between my machine and the other machine, is that the setup of the machine was done with the account that is now always displaying as the "modified by".  It looks like that this account is always used for setting up the connection to SharePoint when no credentials are passed. Hope you can help me in the right direction and have some info if indeed the credentials of the user that has setup SharePoint are cached and how to avoid that that account is used. Also when the password of that account changes, the connection to SharePoint is broken.

 

See below example code of the connection and adding of the SharePoint item.

 

 

ClientContext clientcontext = new ClientContext("https:\\mysharepointurl");

List list = clientcontext.Web.Lists.GetByTitle("MyList");

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem listItem = list.AddItem(itemCreateInfo);
listItem["Title"] = "Test Item";

listItem.Update();
clientcontext.ExecuteQuery();

 

Best Regards,

 

John

  • Rahul-kumar's avatar
    Rahul-kumar
    Brass Contributor
    Hi John, It seems like the issue you're facing is related to the authentication mechanism used in SharePoint 2019 on-premise. By default, when you establish a connection to SharePoint without explicitly providing credentials, it will use the credentials of the user who performed the initial setup of SharePoint on the machine. This can lead to unexpected behavior, such as the "modified by" field displaying that account instead of the account running the app.

    To resolve this issue, you can try the following steps

    Ensure that the user running the app has the necessary permissions to access and modify the SharePoint list. Check the user's permissions in the SharePoint site settings and verify that they have the appropriate rights.

    Explicitly pass the credentials of the user running the app when establishing the connection to SharePoint. This can be achieved by using the SharePoint Client Object Model (CSOM) or REST API and providing the user's credentials programmatically. By doing so, you ensure that the correct user's credentials are used for authentication, regardless of who performed the initial setup.

    If possible, consider using SharePoint's App-Only authentication model, which allows your app to authenticate independently of any specific user account. This way, you can avoid any dependencies on individual user accounts or their setup credentials. App-Only authentication requires additional configuration and setup in SharePoint, but it provides more flexibility and control over authentication.

    Regularly check and update the passwords for the account used to set up SharePoint on the machine. If the password of that account changes, it can indeed break the connection to SharePoint. Keeping the passwords up-to-date ensures a smooth authentication process.

    It's important to note that the exact steps may vary depending on your specific SharePoint configuration and development environment. I recommend consulting SharePoint documentation or seeking assistance from SharePoint experts for more detailed guidance tailored to your specific scenario.

    By following these suggestions, you should be able to ensure that the correct user's credentials are used for authentication in your SharePoint app and avoid any issues related to the setup account.

    Best of luck with your SharePoint development!
    • John_Wil740's avatar
      John_Wil740
      Copper Contributor
      Hi Rahul,

      Many thanks for your reply.

      Indeed it looks like that the account that initial is used to setup SharePoint is now the account that is used to connect to SharePoint when no credentials are supplied.

      The thing is that it's not easy to change the code for connecting to SharePoint, the original setup of the code is that no credentials are passed and the credentials running the Windows Service (which include the csom code) is used for connection to SharePoint.

      Is there some option to change the account from the inital setup account to a different account? Also where to change the password at the moment the password changes in AD?

      Hope you can help.

      Best Regards,

      John

Share

Resources