'Call https://login.microsoftonline.com/{tanent ID}/oauth2/token from sharepoint designer workflow
I am trying to call 'https://login.microsoftonline.com/{tanent ID}/oauth2/token' from sharepoint designer workflow, but the http call keeps throwing Bad Request Error.
I created two dictionary for requestHeader and requestContent. but it seems the API accepts content as x-www-form-urlencoded or as text but not as JSON. But passing a request content in dictionary always pass it as JSON and result in a Bad Request.
Please let me know if anyone have tried calling https://login.microsoftonline.com to get access token.
Thanks Nidhi
Solution 1:[1]
try with this, works for me:
List<KeyValuePair<string, string>> values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("client_id", appSettings.ClientId),
new KeyValuePair<string, string>("client_secret", appSettings.ClientSecret),
new KeyValuePair<string, string>("scope", appSettings.Scope),
new KeyValuePair<string, string>("grant_type", appSettings.GrantType),
new KeyValuePair<string, string>("resource", appSettings.Resource)
};
string requestUrl = $"{appSettings.UrlApiSharePoint}{appSettings.TenantId}/oauth2/token";
FormUrlEncodedContent requestContent = new FormUrlEncodedContent(values);
HttpResponseMessage response = await _httpClient.PostAsync(requestUrl, requestContent);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sergiokml |
