You can configure or update the OAuth 2.0 token sending strategy of a REST host by adding custom scripting to your workflow.

The use case in this procedure demonstrates how you can use a custom workflow to switch your REST host authorization strategy via scripting.

Procedure

  1. Log in to the Automation Orchestrator Client.
  2. Navigate to Library > Workflows and select New Workflow.
  3. Add a name for the workflow and click Create.
  4. Navigate to the Schema tab and add a Scriptable task workflow element.
  5. Add the following input and output parameters to the workflow element:
    Input or Output Name Type
    Input host REST:RESTHost
    Input token string
    Output result REST:RESTHost
  6. Under the Scripting tab, add the following script.
    var oldAuth = host.authentication
    var ouath20type = "OAuth 2.0"
    if (oldAuth.type !== ouath20type) {
        System.log ("REST host isn't using" + ouath20type);
        result = host;
    } else {
        var oldStrategy = oldAuth.rawAuthProperties[1]
        if (oldStrategy === "Query parameter") {
            var newStrategy = "Authorization header";
        } else {
            var newStrategy = "Query parameter"
        }
        var newAuth = RESTAuthenticationManager.createAuthentication ("OAuth 2.0", [token, newStrategy]);
        host.authentication = newAuth;
        result = RESTHostManager.updateHost(host);
    }

    You can also use oldAuth.getRawAuthProperty(1) instead of oldAuth.rawAuthProperties[1]. Both work in the same way.

  7. Save the workflow.
  8. To change the token sending strategy of your REST host, run the workflow.

What to do next

You can verify what token sending strategy your REST host uses by navigating to Inventory > REST-Host, selecting your host, and checking the Authorization entry.