Using Server-to-Server authentication with Power Automate(Flow)

Power Automate(flow) makes automation with Dynamics 365 very easy to setup and configure without the need for a developer in most cases. While there are times we could run the automation for ourselves often times we need to share them or use it across the board.

While it's okay to run it under the user it's best to run it under a service account, so even if someone were to leave the organization it would not impact the flows if they are running under the context of a service account.

Fortunately Power Automate currently supports this. First let's add Common Data Service connector and than add new connection as below.

Now you should see the below screen, select Connect with Service Principal

Clicking this would show us the login screen. We now need to create an App Registration in Azure under the Azure Active Directory and populate the details as shown below. Behind the scenes it follows the client credential grant flow to securely connect to the target environment using OAuth 2.0 authentication .

One quick way to get the Tenant Id is as below

Make sure to add the PowerApps Runtime Service delegated permissions for your application you created and also create the Application User in Dynamics 365 and grant the appropriate security role that you need.

Once a connection is created you can now use the triggers and actions for the target environment and continue designing your Power Automate.