Overview
This article is a follow up to xRM Formula #276 - Trigger Power Automate Flow with Quick Button. This time however, we will be calling a Power Automate where the HTTP request is secured to 'Any user in my tenant'.
For this example, we are going to perform a simple operation of capitalizing the Account name.
Configure the App Registration / Application User
App Registration
You will need to configure an App Registration in Entra ID on Azure for this:
API Permission
You will need to give the App Registration API permission for Power Automate.
It will need User -> Access Microsoft Flow as signed in user
Admin Consent
After you add the permission, Admin consent will need to be granted.
Secret Key
You will also need to create a secret key to access the App Registration:
You will need 3 pieces of information from this App Registration in order to access it:
- Application ID (available in the Overview)
- Secret
- Tenant ID
North52 xCache
To securely store the information from the App Registration we use an xCache record.
Only System Administrators or specifically authorized users will be able to access this value. Additionally, if we have different values for Dev/Test/Production environments we can use separate xCache values for these and the Formula will use the appropriate value at runtime.
- Open the North52 App
- Navigate to Business Process Activities > N52 xCache
- Create a new xCache record
- Enter PowerAutomate for the Category
- Add AppID to the Base Key so that the full BaseKey name is PowerAutomate_AppID
- In the Value Information tab enter your Application ID into the Value (Secured) field
- Click Save
Repeat the above for Tenant ID and for Secret so you will have created 3 xCache records
- PowerAutomate_AppID
- PowerAutomate_TenantID
- PowerAutomate_Secret
North52 Formula
We need to amend the original Formula to add an additional step. We will use the function AzureADGetTokenV2() to retrieve the Bearer Token that we will need to use to call the Power Automate.
This token will then become a third input into the ExecuteMsFlowRequest function:
SmartFlow( SetVar('token', AzureADGetTokenV2(xCacheGetGlobal('PowerAutomate_TenantID'), SetRequestParams( 'scope', 'https://service.flow.microsoft.com//.default', 'client_id', xCacheGetGlobal('PowerAutomate_AppID'), 'client_secret', xCacheGetGlobal('PowerAutomate_Secret'), 'grant_type', 'client_credentials') ) ), ExecuteMSFlowRequest( xCacheGetGlobal('PowerAutomate_HttpPostUrl'), CreateJObject( CreateJProperty('recordId', [account.accountid]), CreateJProperty('accountName', [account.name]) ), 'Bearer ' + GetVar('token') ) )
You can now successfully call the secured Power Automate using the Bearer Token.