'How to adapt the custom code section in the PowerApps connector config to allow a OAuth 2.0 resource owner password credentials Grant type
I am trying to create a custom connection in PowerApps that calls a REST API which requires oauth2 authentication with the password credentials Grant type. I have set up the connection to the API successfully in Postman using Grant Type: Password Credentials and sending the relevant username and password. However, when I try to create the connection in Powerapps there are no fields for 'Grant Type' or to send the username and password. This appears to be a known limitation of Powerapps.
As a workaround, I was wondering whether the custom code field in the custom connector setup could be adapted to send the relevant credentials along with the existing request data, given that the documentation states that Custom code transforms request and response payloads beyond the scope of policy templates.
Here is the boiler plate custom code in C#
public class Script : ScriptBase
{
public override async Task<HttpResponseMessage> ExecuteAsync()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = CreateJsonContent("{\"message\": \"Hello World\"}");
return response;
}
}
Does anyone know how to adapt this to send hard coded key value pairs, along the lines of {"Grant Type" : "Password Credentials"} and {"UserName" : "Foo", "Password" : "Bar"} in the request payload, alongside existing information that is sent?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
