<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Custom connector -  HMAC authentication in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8096#M3399</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;DIV class=""&gt;I'm working on trying to integrate the Lexsynergy API with Workato, but I've hit a roadblock. It seems I can't use the standard HTTP connector due to their specific HMAC authentication requirements. I tried building a custom connector, but I could use some guidance.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Here's the key challenge: Lexsynergy requires a unique "Authorization" header for each request, which involves:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Dynamic Timestamp:&lt;/STRONG&gt; Including the current Unix timestamp.&lt;DIV class=""&gt;&lt;STRONG&gt;Nonce Generation:&lt;/STRONG&gt; Generating a unique random string (UUID v4).&lt;BR /&gt;&lt;STRONG&gt;Signature Calculation:&lt;/STRONG&gt; Computing an HMAC-SHA256 hash of a string constructed from various elements.&lt;BR /&gt;&lt;DIV class=""&gt;&lt;A href="https://portal.lexsynergy.com/uploads/lexsynergy-api_latest.html#introduction" target="_blank" rel="noopener"&gt;https://portal.lexsynergy.com/uploads/lexsynergy-api_latest.html#introduction&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;BR /&gt;A unique URL, method and body need to be signed for each request and it looks like only the URL and method are available as special variables in the &lt;STRONG&gt;apply&lt;/STRONG&gt; key's context.&lt;BR /&gt;&lt;A href="https://docs.workato.com/developing-connectors/sdk/sdk-reference/connection/authorization.html#apply" target="_blank" rel="noopener"&gt;https://docs.workato.com/developing-connectors/sdk/sdk-reference/connection/authorization.html#apply&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;This is what I have so far. A working connection but that's it. The test block works only because that endpoint doesn't require a body and I could put an empty string.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;{
  title: 'Lexsynergy',

  connection: {
    fields: [
      {
        name: 'api_key',
        optional: false,
        hint: 'Your Lexsynergy API key'
      },
      {
        name: 'api_secret',
        optional: false,
        hint: 'Your Lexsynergy secret key',
        control_type: 'password'
      }
    ],
    authorization: {
      type: 'custom_auth',
      acquire: lambda do |connection|
      end,
      apply: lambda do |connection|
      end
    },

    base_uri: lambda do |_connection|
      'https://api.lexsynergy.com/1.9/'
    end
  },

  test: lambda do |connection|
    url = 'https://api.lexsynergy.com/1.9/tlds.json'
    api_key = connection['api_key']
    api_secret = connection['api_secret']
    request = call(:request_signer, api_key, api_secret, 'GET', url, '')
    get(url).headers('Authorization': request['authorization_header'])
  end,

  custom_action: true,

  actions: {},

  triggers: {},

  methods: {
    request_signer: lambda do |api_key, api_secret, method, url, body|
      # Calculate timestamp and nonce
      timestamp = now.to_i.to_s
      nonce = uuid
      realm = 'api'

      # Construct the string to sign
      string_to_sign = "#{realm}\n#{api_key}\n#{nonce}\n#{timestamp}\n#{method.upcase}\n#{url}\n#{body}\n"

      # Generate HMAC signature
      signature = string_to_sign.hmac_sha256(api_secret)
      encoded_signature = signature.encode_base64

      # Construct the Authorization header
      authorization_header = "lexsynergy-http-hmac realm=#{realm}&amp;amp;key=#{api_key}&amp;amp;nonce=#{nonce}&amp;amp;timestamp=#{timestamp}&amp;amp;signature=#{encoded_signature}"
      { 'authorization_header' =&amp;gt; authorization_header }
    end
  },

  object_definitions: {},

  pick_lists: {}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;BR /&gt;Appreciate all the help I can get on this one!&lt;/DIV&gt;</description>
    <pubDate>Tue, 22 Oct 2024 18:27:58 GMT</pubDate>
    <dc:creator>bender</dc:creator>
    <dc:date>2024-10-22T18:27:58Z</dc:date>
    <item>
      <title>Custom connector -  HMAC authentication</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8096#M3399</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;DIV class=""&gt;I'm working on trying to integrate the Lexsynergy API with Workato, but I've hit a roadblock. It seems I can't use the standard HTTP connector due to their specific HMAC authentication requirements. I tried building a custom connector, but I could use some guidance.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Here's the key challenge: Lexsynergy requires a unique "Authorization" header for each request, which involves:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Dynamic Timestamp:&lt;/STRONG&gt; Including the current Unix timestamp.&lt;DIV class=""&gt;&lt;STRONG&gt;Nonce Generation:&lt;/STRONG&gt; Generating a unique random string (UUID v4).&lt;BR /&gt;&lt;STRONG&gt;Signature Calculation:&lt;/STRONG&gt; Computing an HMAC-SHA256 hash of a string constructed from various elements.&lt;BR /&gt;&lt;DIV class=""&gt;&lt;A href="https://portal.lexsynergy.com/uploads/lexsynergy-api_latest.html#introduction" target="_blank" rel="noopener"&gt;https://portal.lexsynergy.com/uploads/lexsynergy-api_latest.html#introduction&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;BR /&gt;A unique URL, method and body need to be signed for each request and it looks like only the URL and method are available as special variables in the &lt;STRONG&gt;apply&lt;/STRONG&gt; key's context.&lt;BR /&gt;&lt;A href="https://docs.workato.com/developing-connectors/sdk/sdk-reference/connection/authorization.html#apply" target="_blank" rel="noopener"&gt;https://docs.workato.com/developing-connectors/sdk/sdk-reference/connection/authorization.html#apply&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;This is what I have so far. A working connection but that's it. The test block works only because that endpoint doesn't require a body and I could put an empty string.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;{
  title: 'Lexsynergy',

  connection: {
    fields: [
      {
        name: 'api_key',
        optional: false,
        hint: 'Your Lexsynergy API key'
      },
      {
        name: 'api_secret',
        optional: false,
        hint: 'Your Lexsynergy secret key',
        control_type: 'password'
      }
    ],
    authorization: {
      type: 'custom_auth',
      acquire: lambda do |connection|
      end,
      apply: lambda do |connection|
      end
    },

    base_uri: lambda do |_connection|
      'https://api.lexsynergy.com/1.9/'
    end
  },

  test: lambda do |connection|
    url = 'https://api.lexsynergy.com/1.9/tlds.json'
    api_key = connection['api_key']
    api_secret = connection['api_secret']
    request = call(:request_signer, api_key, api_secret, 'GET', url, '')
    get(url).headers('Authorization': request['authorization_header'])
  end,

  custom_action: true,

  actions: {},

  triggers: {},

  methods: {
    request_signer: lambda do |api_key, api_secret, method, url, body|
      # Calculate timestamp and nonce
      timestamp = now.to_i.to_s
      nonce = uuid
      realm = 'api'

      # Construct the string to sign
      string_to_sign = "#{realm}\n#{api_key}\n#{nonce}\n#{timestamp}\n#{method.upcase}\n#{url}\n#{body}\n"

      # Generate HMAC signature
      signature = string_to_sign.hmac_sha256(api_secret)
      encoded_signature = signature.encode_base64

      # Construct the Authorization header
      authorization_header = "lexsynergy-http-hmac realm=#{realm}&amp;amp;key=#{api_key}&amp;amp;nonce=#{nonce}&amp;amp;timestamp=#{timestamp}&amp;amp;signature=#{encoded_signature}"
      { 'authorization_header' =&amp;gt; authorization_header }
    end
  },

  object_definitions: {},

  pick_lists: {}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;BR /&gt;Appreciate all the help I can get on this one!&lt;/DIV&gt;</description>
      <pubDate>Tue, 22 Oct 2024 18:27:58 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8096#M3399</guid>
      <dc:creator>bender</dc:creator>
      <dc:date>2024-10-22T18:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Custom connector -  HMAC authentication</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8101#M3403</link>
      <description>&lt;P class=""&gt;Hi,&lt;/P&gt;&lt;P class=""&gt;Good day!&lt;/P&gt;&lt;P class=""&gt;We do have a sample connector that uses HMAC, which you can find in our Community Library. I have included the link for your convenience:&amp;nbsp;&lt;A href="https://app.workato.com/custom_adapters/125161/code?community=true" target="_blank" rel="noopener"&gt;https://app.workato.com/custom_adapters/125161/code?community=true&lt;/A&gt;.&lt;/P&gt;&lt;P class=""&gt;This should provide you with a good starting point for building your custom connector.&lt;/P&gt;&lt;P class=""&gt;If you require further assistance or have any specific questions, I suggest submitting a ticket to our Support Portal. Our team of experts will be more than happy to assist you with any further queries or concerns you may have.&lt;/P&gt;&lt;P class=""&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 07:45:45 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8101#M3403</guid>
      <dc:creator>julie-reyes</dc:creator>
      <dc:date>2024-10-24T07:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Custom connector -  HMAC authentication</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8110#M3408</link>
      <description>&lt;P&gt;Thank you, that was indeed helpful in finding a solution.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 17:30:50 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/custom-connector-hmac-authentication/m-p/8110#M3408</guid>
      <dc:creator>bender</dc:creator>
      <dc:date>2024-10-25T17:30:50Z</dc:date>
    </item>
  </channel>
</rss>

