How To Perform A SharePoint App-Only Authentication In Power Automate

Introduction

  • In this article, we will learn how can we perform SharePoint app-only authentication in Power Automate.
  • Here in this article, we will get users from the SharePoint group through SharePoint app-only authentication in Power Automate.
  • SharePoint App-Only in older, but it is useful in many scenarios.
First, we will learn how to create a SharePoint App for authentication.
 

How to create a SharePoint App

 
Step 1
 
Navigate to your site collection and then open the appregnew.aspx page.
 
https://{tenant name}.sharepoint.com/_layouts/15/appregnew.aspx
 
Step 2
 
On this page, click on the Generate button to generate a client ID and client secret.
How To Perform SharePoint App Only Authentication In Power Automate
Step 3
 
Store the retrieved information (client ID and client secret). We will need this in the next steps.
 
Step 4
 
In the Title field, type the name of the App. For App Domain type www.localhost.com and to Redirect URI, type https://www.localhost.com.
How To Perform SharePoint App Only Authentication In Power Automate
Step 5
 
Now click on the Create button.
 
Step 6
 
Now we need to grant permission to the newly created app. To grant permission, go to the appinv.aspx page of your site.
 
https://{tenant name}.sharepoint.com/_layouts/15/appinv.aspx
 
Step 7
 
Once the page is loaded, add the client ID in App Id field and click on the Lookup button.
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 8
 
On clicking the Lookup button, it will fill in other information like Title, App Domain, and Redirect URL. 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 9
 
Now in a Permission Request XML, enter the below XML.
  1. <AppPermissionRequests AllowAppOnlyPolicy="true">
  2. <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
  3. </AppPermissionRequests>
Step 10
 
Now click on the Create button. When you click on the Create button, it will redirect to a permission consent dialog. Press Trust It to grant the permissions:
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 11
 
Now our SharePoint app is ready, so let’s move to the Power Automate.
 

How to use this Client ID and Client Secret in Power Automate

 
Step 1
 
We will use the HTTP request action of Power Automate, which requires a premium license.
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 2
 
We will need the below IDs:
  • Client ID, which we have generated while creating App in SharePoint site.
  • Client Secret, which we have generated while creating App in SharePoint site.
  • Tenant ID, to get the tenant ID, go to the https://portal.azure.com/ and go to Azure Active Directory. Here you can see your tenant ID.
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 3
 
Now first, we need to get the token using client ID client secret, and tenant ID. To get the token, add the HTTP request action in Power Automate and select all the parameter values as below.
 
Method
Post
URI
https://accounts.accesscontrol.windows.net/{tenant id}/tokens/OAuth/2
Headers
Content-Type: application/x-www-form-urlencoded
Body
grant_type=client_credentials&client_id={CLIENT ID}@{TENANT ID}&client_secret={CLIENT SECRET} =&resource=00000003-0000-0ff1-ce00-000000000000/{TENANT NAME}.sharepoint.com@{TENANT ID}
 
 How To Perform SharePoint App Only Authentication In Power Automate
 
Step 4
 
Now add the compose action and select the below formula in the Inputs field.
 
body('Get_SP_Token')['access_token']
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 5
 
Now again, add HTTP request action and select the value of the parameter as shown below.
 
Method
GET
URI
https://{TENANT NAME}.sharepoint.com/ /_api/web/sitegroups/getbyname(‘{SHAREPOINT GROUP NAME}’)/users
Headers
Accept: application/json;odata=verbose
Authorization: Bearer outputs('Compose')
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 5
 
Now you can test the flow. In the above HTTP request action (Get SP Group Users), you can see the users of the group in the Body section once flow execution is completed.
 
How To Perform SharePoint App Only Authentication In Power Automate
 
Step 6
 
Now you can use Apply to each action to perform any action on each user.
 

Summary

 
This is how we can perform a SharePoint app-only authentication in Power Automate. I hope this article will be helpful!