My ultimate goal is to set up programmatic access to our SharePoint file storage so that our code can write files to the site directly. To this end, I've been testing the SharePoint API under the following parameters:
- Language: C#
- REST Library: REST Sharp
- Environment: LINQPad
Here is the code that I've been executing to attempt to acquire an Access Token:
var clientId = "[APPLICATION ID]"; var clientSecret = "[CLIENT SECRET]"; var client = new RestClient("https://login.microsofttonline.com/[TENANT ID]/oauth2/2.0/token"); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/x-www-form-urlencoded"); request.AddParameter("application/x-www-form-urlencoded", "client_id=" + clientId + "&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default"+"&client_secret=" + clientSecret + "&grant_type=client_credentials", ParameterType.RequestBody); IRestResponse response = client.Post(request); response.Dump();
.Dump() method is specific to LINQPad - it presents a formatted display of all the data in the object. When this code is run in LINQPad, the ResponseCode is 200 OK, but the Content is completely blank (ContentLength = 0). The Content that is expected is a JSON object that includes the Access Token and an expiration (in seconds). The Microsoft documentation says nothing about this possibility.