1. Home
  2. Troubleshooting
  3. Workflow Automations fails with website authentication (Basic Auth)

Workflow Automations fails with website authentication (Basic Auth)

This manual describes a common issue with workflow automation when using authentication on your website. Whether using .htaccess to limit access or other forms of basic authentication, you might encounter issues with your automated workflows. This is because the internal requests made by the Automations (Flows) can’t authenticate to the server by default (As they are just simple HTTP requests).

But don’t worry, we have a solution. We’ve crafted a simple PHP snippet that allows you to authenticate internal requests using your Basic Auth credentials. Here’s how to do it:

The Solution: A PHP Snippet

This PHP function that hooks the WP Webhooks plugin’s HTTP request arguments for internal Flow actions while adding an Authorization header to the HTTP request, which includes your Basic Auth credentials.

add_filter( 'wpwhpro/flows/fire_flow/http_args', 'wpwh_custom_apply_basic_authentiaction', 10, 3 );

function wpwh_custom_apply_basic_authentiaction( $http_args, $endpoint_url, $webhook ) {
    
    $username = 'Your Username';
    $password = 'The password';

    if( ! empty( $username ) && ! empty( $password ) ){
        $http_args['headers']['Authorization'] = 'Basic ' . base64_encode( $username . ':' . $password );
    }

    return $http_args;
}

How to Implement the Solution

  1. Backup Your Site
    Before making any changes, it’s always a good idea to back up your website. This way, if anything goes wrong, you can easily revert to the previous state.
  2. Access Your Site’s Files
    Next, you need to access your site’s files. This can be done through your hosting provider’s cPanel or any FTP client.
  3. Find Your Child Theme’s functions.php File
    The code snippet needs to be added to your child theme’s functions.php file. You can find this file in the directory wp-content/themes/your-theme-name/. Please make sure it is the child theme and not the main theme as otherwise your changes will be overwritten with the next theme update.
  4. Edit the Functions File
    Open the functions.php file in a text editor. Paste the code at the bottom of the file.
  5. Replace the Credentials
    Replace Your Username and The password with your actual Basic Auth credentials.
  6. Save and Upload the File
    Once you’ve made the changes, save the functions.php file and upload it back to your server.
  7. Check Your Site
    After you’ve uploaded the file, check your site to make sure everything is working as expected and give the Flow another try. This time, the actions will be able to communicate internal using the provided authentication credentials.

You can, of course, implement this snippet in a custom plugin as well.

That’s all you need to do. Happy automating!

Updated on May 14, 2023

Was this article helpful?

Related Articles