How to allow my C# apps (non-forms, non-web based) application authenticate & interact with OneDrive? (That is to say, completely programmatically.)
So far:
-Application registered, have client id & secret.
-Enabled both web & phone.
-Personal, not Business.
-Client token flow appears to be for interactive, so using code.
-Tried the OneDrive SDK, but it just kept saying it couldn't authenticate (not why).
-Now hand-rolling requests.
As web client code:
async Task<string> GetStringFromURLAsync(string theURL)
{
string urlContents = "";
System.Net.Http.HttpClient c = null;
try
{
c = new System.Net.Http.HttpClient();
c.Timeout = new System.TimeSpan(0, 0, 30); // 30 seconds
Task<string> asyncResp = c.GetStringAsync(theURL);
urlContents = await asyncResp;
Console.WriteLine("success...");
}
[catch...]
return urlContents;
}
Called by:
Task<string> tGetContent = GetStringFromURLAsync(ai.fullTokenRequestURI);
string httpResponseBody = tGetContent.Result;
(ai is a struct holding client id, url, etc.)
If it is not possible to roll your own and get the correct responses, then which SDK should I be using?
This fares no better:
this.oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
authInfo.cient_id,
authInfo.redirect_url,
authInfo.scopes);
await this.oneDriveClient.AuthenticateAsync();
The OD API simply complains:
OneDrive reported the following error:
Code: AuthenticationFailure
Message: Failed to retrieve a valid authentication token for the user.