Skip to content

Instantly share code, notes, and snippets.

@mmcguff
Created July 25, 2020 11:53
Show Gist options
  • Save mmcguff/ed8842a6605a0d5f49d847508349a5c4 to your computer and use it in GitHub Desktop.
Save mmcguff/ed8842a6605a0d5f49d847508349a5c4 to your computer and use it in GitHub Desktop.
{
title: 'My connector',
connection: {
fields: [
{
name: "token",
control_type: "string",
label: "Bearer token",
optional: false,
hint: "Available in 'My Profile' page"
}
],
authorization: {
type: 'custom_auth',
apply: lambda do |connection|
headers("Authorization": "Bearer #{connection["token"]}")
end
}
},
test: {
# Some code here
},
actions: {
# Some code here
},
triggers: {
# Some code here
},
object_definitions: {
# Some code here
},
picklists: {
# Some code here
},
methods: {
# Some code here
}
}
{
title: 'My Zoho connector',
connection: {
fields: [
{
name: 'email'
},
{
name: 'password',
control_type: 'password'
}
],
authorization: {
type: 'custom_auth',
acquire: lambda do |connection|
{
authtoken:
get('https://accounts.zoho.com/apiauthtoken/nb/create').
params('SCOPE' => 'ZohoCRM/crmapi',
'EMAIL_ID' => connection['email'],
'PASSWORD' => connection['password'],
'DISPLAY_NAME' => 'Workato test adapter').
response_format_raw[/(?<=AUTHTOKEN=)\h+/]
}
end,
refresh_on: [
# Three ways to match:
401, # Integer HTTP response code.
'Unauthorized', # String that equals the whole body or whole title of the error response.
/Unauthorized/, # Regex that matches with the body or title of the error response.
/Invalid Ticket Id/ # The actual "signal" that we need to re-authorize in Zoho.
],
detect_on: [
# Two ways to match: String (matches whole body of the response), and:
/^\{"response":\{"error"/, # Regex that matches the body of the response.
],
apply: lambda do |connection|
params(authtoken: connection['authtoken'])
end
}
},
test: {
# Some code here
},
actions: {
# Some code here
},
triggers: {
# Some code here
},
object_definitions: {
# Some code here
},
picklists: {
# Some code here
},
methods: {
# Some code here
}
}
{
title: 'My Purecloud connector',
connection: {
fields: [
{
name: 'client_id',
label: 'Client ID',
optional: false
},
{
name: 'client_secret',
label: 'Client secret',
control_type: 'password',
optional: false
}
],
authorization: {
type: "oauth2",
authorization_url: lambda do |connection|
params = {
response_type: "code",
client_id: connection["client_id"]
}.to_param
"https://login.mypurecloud.com/oauth/authorize?" + params
end,
acquire: lambda do |connection, auth_code|
response = post("https://login.mypurecloud.com/oauth/token").
payload(
grant_type: "authorization_code",
code: auth_code,
redirect_uri: "https://www.workato.com/oauth/callback"
).
user(connection["client_id"]).
password(connection["client_secret"]).
request_format_www_form_urlencoded
# After defining the POST method, we now need to define the output of the acquire block in a fashion that we can recognise
[
{
access_token: response["access_token"],
refresh_token: response["refresh_token"],
},
nil,
{ instance_id: nil } # Optional. Will be merged into connection hash
]
end,
apply: lambda do |connection, access_token|
headers("Authorization": "Bearer #{connection["access_token"]}")
end
}
},
test: {
# Some code here
},
actions: {
# Some code here
},
triggers: {
# Some code here
},
object_definitions: {
# Some code here
},
picklists: {
# Some code here
},
methods: {
# Some code here
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment