OBLYTECH Logo
OBLYTECH Logo

Authentication profile API for setting authentication method

setAuthenticationProfile is a RESTMessageV2 method that attaches a stored credential to an outbound REST message at runtime. It takes a profile type, basic or oauth2, and the sys_id of a profile record, and returns nothing. This page covers the arguments, the records they point to, and the limits that decide whether a call succeeds.

What the method takes and what it returns

The method is written setAuthenticationProfile(String type, String profileId). It sets the credentials for a REST message from a profile that already exists, either a basic auth profile or an OAuth 2.0 profile. Both arguments are strings.

The type argument accepts two values. The value basic selects basic authentication, and oauth2 selects OAuth 2.0.

The profileId argument is a sys_id, not a display name. The table it points to depends on the type. With basic, the sys_id identifies a Basic Auth Configuration record in the sys_auth_profile_basic table. With oauth2, it identifies an OAuth Entity Profile record in the oauth_entity_profile table. Passing a basic sys_id with the oauth2 value, or the reverse, pairs an argument with the wrong kind of record.

The method returns void. A script gets no success value back from it, so the outcome appears in the request itself: the status code the call returns and the body the receiving system sends back. Both can be read from the response object that execute() returns.

A minimal call follows this pattern:

var sm = new sn_ws.RESTMessageV2('<REST_message_record>', 'get');
sm.setAuthenticationProfile('oauth2', '<oauth_entity_profile_sys_id>');
var response = sm.execute();
var status = response.getStatusCode();

The RESTMessageV2 API runs in the sn_ws namespace. The constructor takes the name of a REST message record and the HTTP method to use, so that record has to exist before the script runs.

Creating the profile record first

The method attaches a profile that already exists, so the record is created before the call is written. The two profile types are created in different places, and each has its own role requirement.

Basic authentication profile

Creating one requires the web_service_admin role. Go to All, then System Web Services, then REST Message. Open a REST message record and set Authentication type to Basic. Click the reference lookup icon beside Basic auth profile, choose New, enter a descriptive name, the username and the password to send, and click Submit. The profile can then be used by one or more REST messages.

Older messages carry a Basic (Simple) choice in the Authentication type list. That choice appears on REST messages configured before the Geneva release and is kept for compatibility with them. REST messages created in Geneva or later should use Basic.

OAuth 2.0 profile

This setup needs both the web_service_admin and oauth_admin roles. Three things must be in place first. An OAuth provider has to exist in the OAuth application registry with the client information for that provider. That provider must have an associated OAuth 2.0 profile. The REST message’s HTTP methods must not be set to use a MID Server.

To create the provider, go to All, then System OAuth, then Application Registry, click New, and choose Connect to a third party OAuth Provider. Enter a name, the client ID and client secret issued by the provider, and set the default grant type. In the worked example, the default grant type is Authorization Code. Enter the authorization, token, redirect and token revocation URLs the provider specifies. The redirect URL must match the one registered with the provider. Right-click the form header and save.

Saving the provider creates an OAuth Entity Profile record. That record is the one whose sys_id goes into the profileId argument. Next, add the scopes the integration needs in the OAuth Entity Scopes list, open the automatically created profile, add the scope in the OAuth Entity Profile Scopes list, and click Update.

On the REST message, set Authentication type to OAuth 2.0 and select the OAuth profile that holds the credentials to send. Save by right-clicking the form header. Click the Get OAuth Token related link. Depending on the provider, a separate window may ask for confirmation before the token is issued. Complete those steps, then test the message.

How the attached profile fits the message and its HTTP methods

Authentication can be set on a REST message as a whole, or on each HTTP method that belongs to it. An HTTP method’s Authentication type defaults to Inherit from parent, which means the method uses whatever its REST message is set to. Setting the method to No authentication switches credentials off for that call. Setting it to basic or OAuth overrides the parent for that method alone.

HTTP methods are created from the REST message record when it is first created, and several default methods are created automatically. Changes made later to the REST message record are not applied to existing HTTP methods automatically, so an endpoint or authentication change has to be made on each method that needs it. The scripted method sets credentials on the RESTMessageV2 object the script holds, using the profile that the sys_id points to.

Related credential methods on RESTMessageV2

Three other RESTMessageV2 methods also set credentials on the same object. Each one overrides a value defined on the REST message record, which is the main point to keep in mind when more than one of them appears in a script.

Method Arguments What it does
setBasicAuth String userName, String userPass Sets basic auth headers for the message. Overrides basic auth values defined on the REST message record.
setMutualAuth String profileName Sets the mutual authentication protocol profile. Overrides the protocol profile selected on the REST message record.
setRequestorProfile String requestorContext, String requestorId Overrides the default requestor profile so an OAuth access token is retrieved for a different requestor. Applies only to REST messages configured for OAuth 2.0, and the method is optional.

The practical difference is where the secret lives. setBasicAuth takes the username and password as arguments, so they sit in the script. setAuthenticationProfile takes a sys_id, so the credentials stay in the profile record the admin form created, and the script carries only the identifier.

Limits that decide whether a call succeeds

Several boundaries decide whether an authenticated call works.

Scope comes first. Creating the RESTMessageV2 object can throw an exception if the REST message does not exist or is not visible because of scope. A scope mismatch is the first cause to rule out when a script fails on that line.

Execution comes second. execute() can throw when the HTTP connection times out, or when there is a problem sending the request itself, including password encryption or decryption. Timeouts are set with setHttpTimeout, which takes milliseconds. The timer runs on the socket, so the call fails only when no data arrives within that window. A value of 10000 allows 10 seconds without data before the timeout fires.

Authentication type comes third. OAuth 2.0 can be used only with messages that are not configured to use a MID Server, and an OAuth 2.0 message cannot be sent through a MID Server. Mutual authentication is supported only with basic authentication. It is not available with OAuth 2.0, and it is not supported with a MID Server.

The API choice matters too. Scripts that send authenticated requests should use RESTMessageV2. The legacy RESTMessage APIs do not support the current authentication formats.

Some capabilities are missing from RESTMessageV2 but available in the REST step of IntegrationHub. These include mutual authentication through a MID Server, multipart requests with attachments, custom Authentication Algorithm profiles, AWS Signature Version 4 authentication, and built-in retry policies. Custom retry logic has to be written in the script. AWS credentials and other custom authentication work only with the REST step, not with the RESTMessage API. A design that needs any of these should choose the REST step before the integration is written.

Routing through a MID Server is a separate option. An HTTP method can send through a MID Server by selecting one in the Use MID Server field on the HTTP method form. That path reaches endpoints behind a firewall or on a private network, and the instance needs an active MID Server to use it.

Mutual authentication profiles

In mutual authentication, the instance presents a client certificate and validates the server certificate, and the server validates the client certificate in return. The instance needs its client certificate uploaded to it, and the web service provider’s trusted server certificate uploaded to it.

The protocol profile is created under All, then System Security, then Protocol Profiles, by clicking New. This step requires the admin role. The protocol name must be unique, contain no upper case letters or special characters, and cannot reuse an existing name such as HTTPS. The client certificate has to be of type Java Key Store or PKCS12 Key Store.

To apply the profile to a REST message, go to All, then System Web Services, then Outbound, then REST Message, and select the record. Select the Use mutual authentication check box, choose the protocol profile in the Protocol profile field, and click Update. This step requires the web_service_admin or admin role. For REST messages, the mutual authentication setting pairs with basic authentication.

Frequently asked questions

What does setAuthenticationProfile return? It returns void. The method sets credentials on the message and gives back nothing, so the outcome has to be read from the status code and body of the request.

Can the second argument be a profile name? No. The second argument is the sys_id of a profile record. A basic sys_id comes from the Basic Auth Configuration table, and an OAuth sys_id comes from the OAuth Entity Profile table.

Which API should a script use with an authenticated REST message? RESTMessageV2. The legacy RESTMessage API does not support the current authentication formats.

Can OAuth 2.0 messages go through a MID Server? No. An OAuth 2.0 message can be used only when it is not configured to use a MID Server.

Can mutual authentication be combined with OAuth 2.0? No. Mutual authentication is supported only with basic authentication.