Creating and configuring a custom connector
In Power Automate, you must use the Custom Connector to communicate with the CDESK server. A Custom Connector in Power Automate is a user-defined connector that allows Power Automate to communicate with external systems or APIs, in this case the CDESK API.
1. After signing in to the Power Automate web interface, click More in the left menu.
2. A menu of options appears; if you don’t see the Custom connectors button, click Discover all.
3. In the Discover all menu, you’ll find Custom connector under the Data list.
4. In the Custom Connectors menu, click New custom connector, and then click Create from blank.
5. After creating the connector, you must fill in the basic connection details.
In the General tab, you must fill in the required fields as follows:
- Scheme: HTTPS
- Host: The address of your CDESK server without the protocol
- Base URL: /api (predefined endpoint for the API on the CDESK server side)
Connector settings on the CDESK side
In the connector settings menu, you need to generate a random and a signing key. You can generate the key by clicking the button on the right side of the field. After generating the key, copy it . Give the connector a descriptive name and click the Create button.
Configuring authentication in Power Automate
After creating the connection OAuth 2.0 in CDESK, you need to configure authentication for the CDESK connector on the Power Automate side.
- In the 2. Security tab of the Power Automate connector settings, select the authentication method OAuth 2.0, and leave Identity provider set to Generic Oauth 2.
- In the Client Secret field, enter the Signing Key you created on the CDESK side in the connectors.
- The Client secret field denotes the user identifier in the CDESK system under which the connector will authenticate and perform individual actions
- From a security perspective, it is strongly recommended to create a separate API user in CDESK who will be assigned only the minimum necessary permissions required to perform specific operations. This reduces the risk of unauthorized access to sensitive data and limits the scope of potential impacts in the event of a compromise of login credentials.
- You can find the user ID in CDESK in the profile section.
- Oauth protocol field – leave as Generic Oauth 2
- Client ID – Enter User ID in CDESK, under which Power Automate will operate
- Client secret – Signature key generated on the CDESK side
- Authorization URL – URL of the OAuth 2.0 authorization endpoint, to which the user is redirected to approve access. Always {URL} /api/auth/oauthauthorize (URL refers to the address of your CDESK server).
- Token URL – URL of the token endpoint used to exchange the authorization code for access token. Always {URL} /api/auth/oauthlogin.
- Refresh URL – The URL of the endpoint used to refresh the access token after it expires. Always {URL} /api/auth/oauthlogin.
- Scope – The scope of permissions that the connector requests during authentication. Permissions are handled on the CDESK server side; this field can remain empty.
After setting the correct values, click the Update Connector button to save the changes.
Configuring Authentication Processing in Power Automate
Due to compatibility with the CDESK authentication mechanism, it is necessary to use a custom script on the Power Automate side that modifies the format of the HTTP request’s authorization header.
When using OAuth 2.0, Power Automate sends the access token in the header by default:
- Authorization: Bearer <access_token>
However, the CDESK API expects a token in the following format:
- Authorization: apitoken < access_token >
For this reason, you must use the following script in the Code section of your custom connector. This script ensures that the authorization header is transformed before the request is sent to the CDESK server:
public class Script: ScriptBase
{
public override async Task<HttpResponseMessage> ExecuteAsync()
{
var authHeader = this.Context.Request.Headers.GetValues(“Authorization”).First();
var token = authHeader.Replace(“Bearer”,””);
this.Context.Request.Headers.Add(“Authorization”,$”apitoken{token}”);
return await this.Context.SendAsync(this.Context.Request, this.CancellationToken);
}
}
To insert the code, you must enable the Code Enabled switch. You can then enter the code into the adjacent text field.
Make sure that no specific action is selected in the drop-down list of operations. In this state, the code is applied globally, meaning it applies to every program block created for your custom connector.
After inserting the code, click the Update Connector button to save the changes.
In this state, the custom connector is fully ready for adding, configuring, and testing individual program blocks and the required functions.