yesterday
Hello,
I'm pretty new to workato and not quite familiar with Ruby.
I need to write a custom connector that authenticates using a POST request passing username/password and receives back an auth token; the Token will then be used in the header of following requests; I'm struggling in identifying the correct form to write the "authorization" block of the "connection" section; I've tried using the following:
14 hours ago - last edited 14 hours ago
Hii @Giorda62 ,
There are a few syntax issues in your code. I’ve adjusted the acquire block below
authorization: {
type: 'custom_auth',
acquire: lambda do |connection|
response = post("https://XXXXXXXXXXX/api/login").
headers('Content-Type': 'application/json').
payload(
username: connection['username'],
password: connection['password']
).request_format_json
{
token: response['token']
}
end,
refresh_on: [401, 403],
apply: lambda do |connection|
headers(Authorization: "Bearer #{connection['token']}")
end
},
base_uri: lambda do |connection|
'https://XXXXXXXXXXX/api'
end
},
test: lambda do |connection|
get("#{connection['BaseURL']}")
end
I hope this works :).