We have a Dynamics 365 instance in our tenant in Azure. We also use ADFS/Entra ID in the tenant.
I want to build a web app that I deploy in Azure, that can fetch data from Dynamics. And I want it to do this using my AD credentials.
The web app is basically the “ASP.NET Core Web App (Razor pages)” template on .Net 8.0 with Authentication type=”Microsoft identity platform”. Conveniently, the sample shows the logged in user in the header so I know that part works.
I then add code to connect to Dynamics, like so:
var connStr = $"AuthType=OAuth;Url={environment};LoginPrompt=Auto;RedirectUri=http://localhost";
client = new ServiceClient(connStr);
I have also made sure “http://localhost” is in the list of valid redirect URIs in the Azure portal for my web app.
It results in the browser opening the “pick an account” dialog. It works, but I need to pick my account all the time, every time. After selecting it I get the message “Authentication complete. You can return to the application. Feel free to close this browser tab”.
How can I pass on the Microsoft identity platform credentials for my webpage to the login to Dynamics, so that I don’t have to select an account every time?