Hi All,
I have requirement to integrate D365 FO with and 3rd party tool.
I have Payment API provided by client with.
I have client ID,secret, scope and token URL
I am trying to generate token and consume it in the API call.
I have written C# library for the same and then I have added it as reference in x project.
I have created a runnable class and trying to call the C# code but I am getting the below error.
Please correct if I am not following right procedure to achieve this.
C# Code
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web;
namespace WTL_6DeeAPIToken
{
public class SixDeeTokenService
{
public static async Task GET6DeeToken()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://xxxxxxxxxxxxx.onmicrosoft.com/gis/.default");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string tokenURL = @"https://login.microsoftonline.com/24f9d756-bf0c-43e9-ad5e-2073ae2d6698/oauth2/v2.0/token";
string grant_type = "client_credentials";
string client_id = "xxxxxxxxxxxxxxxxxxxx";
string client_secret = "xxxxxxxxxxxxxxxxxxxxx";
var form = new Dictionary
{
{"grant_type", grant_type},
{"client_id", client_id},
{"client_secret", client_secret},
};
HttpResponseMessage tokenResponse = await client.PostAsync(tokenURL, new FormUrlEncodedContent(form));
var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
Token tok = JsonConvert.DeserializeObject(jsonContent);
return tok;
}
public class Token
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
[JsonProperty("expires_in")]
public int ExpiresIn { get; set; }
[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }
}
}
}
X Code:
