Stephen McCormick
Stephen McCormick

Reputation: 1796

C# SharePoint Online Remote Authentication

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.

Upvotes: 2

Views: 1495

Answers (1)

Jyotsna Wadhwani
Jyotsna Wadhwani

Reputation: 128

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;
    }

Upvotes: 4

Related Questions