A cloud-based identity and access management service for securing user authentication and resource access
I am accessing API in dyanmics 365 BC using asp.net core 8 token issue
BC Dev
0
Reputation points
When I am accessing the API in Dynamics 365 Business Central using ASP.NET Core 8, but I am facing a token issue
this is my code for token Generate
private async Task<string> GetAccessToken()
{
using var client = new HttpClient();
var url = "https://login.microsoftonline.com/7xxxxxx9/oauth2/v2.0/token";
var body = new Dictionary<string, string>
{
{ "grant_type", "client_credentials" },
{ "client_id", "a3xxxxxx5" },
{ "client_secret", "BFNxxxxxx~" }, // 🔒 move to config later
{ "scope", "https://api.businesscentral.dynamics.com/.default" }
};
var content = new FormUrlEncodedContent(body);
var response = await client.PostAsync(url, content);
var json = await response.Content.ReadAsStringAsync();
var tokenObj = JsonSerializer.Deserialize<TokenResponse>(json);
return tokenObj.access_token;
```}
public class TokenResponse
{
```sql
public string access_token { get; set; }
```}
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Sign in to answer