cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OrenLevy
Frequent Visitor

HTTP request with Bearer Token

I'm trying to use Power Automate to capture a webhook that is being generated by an outside/closed system.

In Power automate I just have simple trigger that is: "When a HTTP request is received" followed by a parser and 200 response.

I can simulate receiving the data using Postman with no issues when using no additional authentication in the header.

When the actual system generates the webhook call, it includes a Bearer token in the header. 

As a result I get the following error: error 401

 

{
"error": {
"code": "DirectApiRequestHasMoreThanOneAuthorization",
"message": "The request has both SAS authentication scheme and 'Bearer' authorization scheme. Only one scheme should be used."
}
}

 

Unfortunately, I can't modify anything in the system that generates the webhook.

I can only subscribe to it as is.

Is there a way to set the Flow HTTP API trigger to ignore the Bearer token and not fail since it now has both (Bearer token and SAS auth)?

 

Thank you

 

Oren

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @divdivsays 

I created an Azure function that consumes the webhook and then redirects it to Power Automate (flow).

The Azure function is more forgiving and I just redirect the payload to flow.

 

I created an Azure function (with no authentication/security).

I added a parameter to the Azure function endpoint url called "disp" to identify the source of the webhook.

Below is the code for the Azure function (they are free up to a certain SLA/consumption).

In a nutshell:

  •  I consume the webhook payload (json).
  • Convert it to a string.
  • Add a json wrapper around it to include the source of the webhook ("disp" parameter)
  • Create an HTTP post response and sends that to Power Automate.

Let me know if that worked for you.

 

Regards

 

Oren Levy

 

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Text;
using System.Net.Http;


private static HttpClient httpClient = new HttpClient();

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{

    string disp = "";
    string flowUrl = "";

    log.LogInformation("C# HTTP trigger function processed a request.");

    // used this additional parameter in the webhook url to identify the source
    string name = req.Query["disp"];
    
    disp = name;
    flowUrl = "ENTER YOUR FLOW HTTP POST URL";

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    
    
    //convert original request to string
    string dataJson = Convert.ToString(data);

    //added a json wrapper on top of the original payload to be able to include the source
    dataJson = "{"+ ((char)34).ToString() + "disp"+ ((char)34).ToString() + ": "+ ((char)34).ToString() + disp + ((char)34).ToString() + ","+ ((char)34).ToString() + "wrapper_data"+ ((char)34).ToString() + ": " + dataJson + "}";

    string responseMessage = string.IsNullOrEmpty(name)
        ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name},   {name}. This HTTP triggered function executed successfully.";


    //create the httpcontent to be sent as a post.
    var httpContent = new StringContent(dataJson, System.Text.Encoding.UTF8, "application/json");
    //send the Post
    var response = await httpClient.PostAsync(flowUrl,httpContent);

    return new OkObjectResult(dataJson);
            
 }

 

 

View solution in original post

2 REPLIES 2
divdivsays
New Member

Hi @OrenLevy - really keen on hearing how you solved for this? 

 

Facing the same exact issue - on capturing a webhook and not able to modify anything on their side to get around the SAS + Bearer Auth schemes error.

Hi @divdivsays 

I created an Azure function that consumes the webhook and then redirects it to Power Automate (flow).

The Azure function is more forgiving and I just redirect the payload to flow.

 

I created an Azure function (with no authentication/security).

I added a parameter to the Azure function endpoint url called "disp" to identify the source of the webhook.

Below is the code for the Azure function (they are free up to a certain SLA/consumption).

In a nutshell:

  •  I consume the webhook payload (json).
  • Convert it to a string.
  • Add a json wrapper around it to include the source of the webhook ("disp" parameter)
  • Create an HTTP post response and sends that to Power Automate.

Let me know if that worked for you.

 

Regards

 

Oren Levy

 

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Text;
using System.Net.Http;


private static HttpClient httpClient = new HttpClient();

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{

    string disp = "";
    string flowUrl = "";

    log.LogInformation("C# HTTP trigger function processed a request.");

    // used this additional parameter in the webhook url to identify the source
    string name = req.Query["disp"];
    
    disp = name;
    flowUrl = "ENTER YOUR FLOW HTTP POST URL";

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    
    
    //convert original request to string
    string dataJson = Convert.ToString(data);

    //added a json wrapper on top of the original payload to be able to include the source
    dataJson = "{"+ ((char)34).ToString() + "disp"+ ((char)34).ToString() + ": "+ ((char)34).ToString() + disp + ((char)34).ToString() + ","+ ((char)34).ToString() + "wrapper_data"+ ((char)34).ToString() + ": " + dataJson + "}";

    string responseMessage = string.IsNullOrEmpty(name)
        ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name},   {name}. This HTTP triggered function executed successfully.";


    //create the httpcontent to be sent as a post.
    var httpContent = new StringContent(dataJson, System.Text.Encoding.UTF8, "application/json");
    //send the Post
    var response = await httpClient.PostAsync(flowUrl,httpContent);

    return new OkObjectResult(dataJson);
            
 }

 

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Kudoed Authors
Users online (2,373)