Hello,
I've done some extensive research on how to use the Authentication flows from Azure AD but the documentation is not clear on what we are trying to achieve.
The following question is similar but has never been really answered:
The problem:
We need to create an external application that we'll interact with the Business Central API WITHOUT user interaction. This external application might run on a scheduled base so the user won't be able to provide credentials
Microsoft Documentation states that we can use 2 types of auth:
1. Azure AD
2. Basic Auth (username web service access key)
Solution number 2 above would work for us, but the documentation says it DOES NOT work in production and therefore it is only useful to explore the API.
We are then forced to use solution 1 (Azure AD), but none of the authentication flows seems to work because they need the user to sign in.
The one I thought it would work is the Client Credentials: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#client-credentials
We tried the following:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(config.ClientId)
.WithClientSecret(config.ClientSecret)
.WithAuthority(new Uri(config.Authority))
.Build();
string[] scopes = new string[] { $"{config.ApiUrl}.default" }; //https://api.businesscentral.dynamics.com/.default
AuthenticationResult result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
The Access Token that the code above return gives a "Unauthorized" code when you make a request to:
api.businesscentral.dynamics.com/.../companies
Can anyone help and provide some guidance?
Thank you,

Report
All responses (
Answers (