2

I am trying to remotely update SharePoint Online data (or self-hosted for that matter) within Azure.Net C# and would prefer to use JSON. I am trying to find how to execute the authentication - I think once I have that I the rest will be pretty straight forward. I have looked at a lot of MS docs and blogs, but none seem to provide a good example of how to do the authentication. For example:

SharePoint Online authentication failure Uses a web request and SOAP data

SharePoint Online: Authenticating.NET Client Object Model in Office 365 Which seems to be using a NuGet package

Get to know the SharePoint REST service Where the REST API with OData is used (but with no good Authenticate example that I can find)

  1. Is there a standard (and easy) way to authenticate?
  2. Does the SharePoint account need to provide a user/password

I probably am missing something - seems like a simple Rest API with an Authenticate would suffice? If someone knows of a good site with a full example that would be awesome.

Community
  • 1
  • 1
Stephen McCormick
  • 1,706
  • 22
  • 38
  • are you developing a console app for this purpose or a sharepoint app? – Jyotsna Wadhwani May 17 '17 at 05:26
  • @JyotsnaWadhwani A service actually. We are trying to allow users to map our data to their share point account collection. Then when the data is submitted to our system our service will move the data to where they want it in share point (kind of like Zapier but not as extensive and specific to our data). Think I have decent grasp of everything other than authentication. – Stephen McCormick May 17 '17 at 17:04

1 Answers1

4

There are many ways to establish the authentication part but the simplest is through the tenant administrator credentials:

Add the tenant administrator username and password to your SharePoint client Context. I think the following code will help you ->

string  _userName="<user email>";
 _securePassword = GetSecureString("<password>");
 _clientContext.Credentials = new SharePointOnlineCredentials(_userName, _securePassword);

function to get password as secure string is

 private static SecureString GetSecureString(String password)
    {
        SecureString securePassword = new SecureString();

        foreach (Char c in password.ToCharArray())
        {
            securePassword.AppendChar(c);
        }
        return securePassword;
    }