When you are using Connectors in PowerApps, each user accessing the PowerApp needs to give permission to the specific connector the first time they use it. If there are multiple connectors, then the user needs to authenticate each of them, as shown below.
For this post, I've built a simple app to display the user's given name. To get the given name, I'm using the Office 365 Users connector.
So, how do we get it without having every user give explicit permissions to the Office 365 Users connector?
Scenario 1 - Getting the Given Name directly from PowerAppsIn this first scenario, I have added the Office 365 connector directly to the PowerApp (View > Data sources > + Add data source > Office 365 Users). The text field, then uses the Default method to set the value using Office365Users.UserProfileV2(User().Email).givenName
No good! Try again.
Scenario 2 - Use PowerApp to call a Flow to retrieve the Given NameIn the second scenario, I have removed the Office 365 connector from the PowerApp and replaced it with a Flow called . This way, the Flow is doing the work with the connector. The Flow is fairly simple in structure as shown below.
I also had to make the following modifications to the PowerApp
- Remove the Office 365 Users connector (View > Data sources > Office 365 Users > ... > Remove). There's no more need for it
- On the Screen1, add a Flow for OnStart (Screen 1 > Actions > Flows > Get Given Name). We need to connect the Flow to the PowerApp when the PowerApp is launched
- Change the function for OnStart to Collect(GivenName,'Get Given Name'.Run(User().Email)). This way, the value will get loaded into a Collection
- Change the text field Default value to First(GivenName).givenname. As the result is stored in a collection, we want to retrieve the first record and get the givenname field.
Save, publish, and try again. Strike 2! The Flow is keeping the context of the user and is still requesting the user for permission.
Scenario 3 - Leverage a Secondary Flow to do all the Connector workIn this third scenario, I am leveraging a secondary flow to access the Office 365 connector to retrieve the user's given name. The secondary flow is invoked using an HTTP trigger.
Here's what the revised first Flow looks like
By doing so, the Flow that is called from the PowerApp and the PowerApp itself have never leverage the Office 365 connector.