Skip to content

PowerApps Connecting from GCC to any Endpoint including Commercial Azure

pierowman edited this page Jun 29, 2021 · 3 revisions

This example is using Azure Blob Storage.

Overview

  1. In Power Apps create a custom connector using Azure Rest API, in this case blob storage
  2. Create a Power Automate create a Flow that will convert the response from the Custom Connector into a format that can be displayed in Power Apps Canvas App
  3. From Power Apps Canvas App, call the Flow to display the response from the Rest API

Security

  • When doing this, careful thought should be put into security
  • Azure Blob Storage - creating a SAS token and setting the appropriate permissions for the use case. Creating Blob SAS token
  • Power Apps for custom connectors by default are limited to the creator but can be expanded. Sharing Custom Connectors
  • Power Automate Flows can be given permissions as well, typically permissions should be set to match permissions set on the Power App. Sharing Power Automate Flows

Creating a Custom Connector that connects to Azure Blob Storage

  1. Create a SAS token
  2. Get the SAS URI should look like: https://myaccount.blob.core.windows.net/?restype=service&comp=properties&sv=2019-02-02&ss=bf&srt=s&st=2019-08-01T22%3A18%3A26Z&se=2019-08-10T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=JBoQmAOAz7qROPEawv%2Bh0bn9ZIWe747N8NnhGQQPNxU%3D
  3. When entering the SAS URI into Custom Connector it UTF-8 encodes it. Yet the SAS URI is already UTF-8 encoded. So to work properly the <some value> part of sig=<some value> needs to be un-encoded, in this case JBoQmAOAz7qROPEawv%2Bh0bn9ZIWe747N8NnhGQQPNxU%3D
  4. Use UTF-8 Decoder to decode the values that are % + number + letter pattern.
  5. Continuing with the same example the values to un-encode are %2B and %3D which become + and =
  6. Resulting in JBoQmAOAz7qROPEawv+h0bn9ZIWe747N8NnhGQQPNxU= this is what needs to be entered into the connector.
  7. When testing the connector you can validate that the SAS token is encoded back to the expected format. Note there maybe some values that do not need to be converted.
  8. In the custom connector you want to make sure that the Azure Blob Storage URI is in the format documented for Azure Blob Storage Rest API. Tip: You can use Postman to validate you have the calls right before entering them into Custom Connector.
  9. Here is an example for Get List Blobs: https://myaccount.blob.core.windows.net/containername?restype=container&comp=list&sp=racwdl&st=2021-05-13T17:38:06Z&se=2022-06-02T01:38:06Z&spr=https&sv=2020-02-10&sr=c&sig=JBoQmAOAz7qROPEawv%2Bh0bn9ZIWe747N8NnhGQQPNxU%3D

Create Power Automate Flow

End 2 End Flow

  1. Create a new Flow
  2. Create a PowerApps trigger
  3. Add the custom connector from above, search by the connectors name
  4. Add a 'Compose' task
  • name it 'Response Body - XML to JSON'
  • click on 'Inputs'
  • select 'Expression'
  • enter json(xml(outputs('GetBlobList').body))
  • Compose Task Example
  1. Save the Flow and Run the Flow. In the run results go to the 'Response Body - XML to JSON' and copy the Raw Output of the 'Outputs'
  2. Add 'Parse Json' task
  • In Content select 'Outputs' from 'Response Body - XML to JSON'
  • For the Schema click 'Generate from sample' paste in the Raw Output.
  • Parse Json Example
  1. Add 'Initialize Variable' task
  • Give it a name
  • Select 'Array' for the Type
  • Initialize Variable Example
  1. Add 'Apply to each' task
  • In the 'Select an output from previous steps' click and select expression
  • Enter body('Parse_JSON')?['EnumerationResults']?['Blobs']?['Blob']
  • Click 'Add an Action' in the 'Apply to each' task
  • Choose 'Append to array variable' task
  • In the Name select the variable created in the previous step
  • In the Value select Name from the Dynamic content from 'Parse Json'
  • Apply to each Example
  1. Add a 'Response' task
  • In the Body select the variable
  • In the 'Response Body JSON Schema'
{
    "type": "array",
    "items": {
        "type": "string"
    }
}
  • Response Task Example

Call Power Automate Flow from Power Apps Canvas App

  1. In a Canvas App create a Button
  2. Configure the button to call the Flow
  • OnSelect fx= ClearCollect(MyResults, MyFlow.Run())
  • Calling a Flow Example
  1. Create an empty Gallery
  2. Set the Gallery Data Source to the collection MyResults used on the button.
  3. Add a text Label to the Gallery
  • Text Label in Gallery Example

Make the Blob name clickable to download file

  1. Add a Label 'baseUrlLabel' and set its text to be the first half of the download blob url https://myaccount.blob.core.windows.net/containername/
  2. Add a Label 'queryStringLabel' and set its text to be the last half of the blob url ?sp=racwdl&st=2021-05-13T17:38:06Z&se=2022-06-02T01:38:06Z&spr=https&sv=2020-02-10&sr=c&sig=JBoQmAOAz7qROPEawv%2Bh0bn9ZIWe747N8NnhGQQPNxU%3D
  3. Edit the Gallery Label's 'OnSelect' to be Launch(baseUrlLabel.Text & ThisItem.Value & queryStringLabel.Text)
  4. You can change the properties of the Gallery Textbox to show as underlined and the text as blue to show as a hyperlink
  • Clickable blob storage file download example