In C#, I'm accessing the SharePoint site context to upload files using a username and password:

using (var ctx = new ClientContext(tenantAdminUrl))
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in ConfigurationManager.AppSettings["Password"].ToCharArray()) passWord.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials(ConfigurationManager.AppSettings["Username"], passWord);


This works fine. But the client does not want to use a designated account for this. Is there a way to use a client ID and client secret to Authenticate?

I am not finding much, if any, documentation about this.



Short answer: Probably not - ClientContext always needs some credentials.

Long answer:
The ClientContext can be authenticatd using some kind of tokens. Search for OAuth/apps/add-in in combination with SharePoint. A starting-point could be this article by Krik Evans or this one.

But I'm guessing you'd need add-in-infrastucture for this (i.e. user accesses SharePoint, from there he is redirected to your add-in - the redirect has all the tokens needed as query-params, your add-in can leverage TokenHelper or SharePointContextProvider to create an authenticated ClientContext)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.