Beta version of the new documentation.

Connector and Authentication Settings

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.

Figure 1: Power Automate for the web main menu

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.

Figure 2: Discover menu, Custom connectors section

4. In the Custom Connectors menu, click New custom connector, and then click Create from blank.

Figure 3: Creating a new empty connector

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)
Figure 4: Basic information about the connector connection

Connector settings on the CDESK side

To configure the connection between and Power Automate using OAuth 2.0, you need to create a connection in your CDESK environment. You can find the connector configuration in the section Global Settings → Connectors, API. Then click the Add Connector button.
Figure 5: Creating an Oauth 2.0 connector
Next, search for “Oauth” in the Connector Type field, select the Oauth 2.0 Connector, and click the Continue button.
Figure 6: Creating a connector

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.

Figure 7: Generating a signing key

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.
Figure 8: Basic Oauth 2.0 settings in Power Automate
Figure 9: Location of the user ID in CDESK
Figure 10: Configuring individual authentication fields
  1. Oauth protocol field – leave as Generic Oauth 2
  2. Client ID – Enter User ID in CDESK, under which Power Automate will operate
  3. Client secret – Signature key generated on the CDESK side
  4. 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).
  5. Token URL – URL of the token endpoint used to exchange the authorization code for access token. Always {URL} /api/auth/oauthlogin.
  6. Refresh URL – The URL of the endpoint used to refresh the access token after it expires. Always {URL} /api/auth/oauthlogin.
  7. 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);

}

}

Figure 11: Inserting code into the Code section

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.