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
- Log in to the Automation Orchestrator Client.
- Navigate to and select New Workflow.
- Add a name for the workflow and click Create.
- Navigate to the Schema tab and add a Scriptable task workflow element.
- 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 |
- 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.
- Save the workflow.
- 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 , selecting your host, and checking the Authorization entry.