microsoft / Dynamics-AX-Integration

Dynamics AX Integration samples and demos.
285 stars 356 forks source link

Clarified how to use AAD web app authentication. #108

Closed Zacch closed 1 year ago

Zacch commented 3 years ago

The sample was using ClientConfiguration.Default.UriString for the operation path, which was causing an error when calling OAuthHelper.GetAuthenticationHeader(true). This patch adds a boolean constant, UseAadWebAppAuthentication, and uses its value to set the correct operation path for the chosen authentication.

The documentation for UriString says "You only need to populate this section if you are logging on via a native app. For Service to Service scenarios in which you e.g. use a service principal you don't need that." I left it unchanged. Then even though I passed true to OAuthHelper.GetAuthenticationHeader and got a valid token, my request to the actual session operation path would just time out.

I spent many hours looking for other solutions and starting to write my own implementation from scratch before I found the problem. This pull request will hopefully save some other developers the effort!