It would be great to hit the ground running with a working example....
public async Task AuthUser()
{
if (serviceUrl != null)
return;
HttpClient authClient;
authClient = new HttpClient();
HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"grant_type","password"},
{"client_id",ConsumerKey},
{"client_secret",ConsumerSecret},
{"username",Username},
{"password",Password}
}
);
var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
HttpResponseMessage message = await authClient.PostAsync(url, content).ConfigureAwait(false);
string responseString = await message.Content.ReadAsStringAsync().ConfigureAwait(false);
if (responseString.Contains("error_description"))
{
Log.Error(String.Format("Salesforce Authorization failed in SalesforeceRestService with: {0}", responseString));
}
else
{
JObject obj = JObject.Parse(responseString);
oAuthToken = (string)obj["access_token"];
serviceUrl = (string)obj["instance_url"];
}
}
Then once authenticated I add it to my header for subsequent call as follows..