[HTTP 401] Unable to create record: Authentication Error - invalid username

Created on 31 July 2023, over 1 year ago
Updated 14 August 2023, over 1 year ago

Problem/Motivation

I have a working Twilio account that I'm using on a D7 site to successfully send SMS messages using SMS Framwork.

I'm trying to use the same Twilio number with the same keys (I created an authentication type key for the SID and also an authentication type key for the Auth key) but when I try to send a test message it fails and the log shows: [HTTP 401] Unable to create record: Authentication Error - invalid username

Steps to reproduce

Install the module, create two keys, try to send a test SMS.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

EDIT: Mistakenly wrote "encryption key" instead of "authentication key"

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇹🇭Thailand AlfTheCat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @AlfTheCat
  • 🇮🇳India nanny1979

    I am getting the same error with D9. SMS is successful with the CURL. When we try the same via the module, it is throwing the authorization error.

  • 🇮🇳India shashank5563 New Delhi

    @nanny1979,

    Please follow the installation instruction.

    Installation

    1. Drupal 8,9 & 10: Add the library via the composer composer require twilio/sdk
    2. Visit 'admin/config/system/twilio' and enter your Twilio account SID, Auth Token, and Phone number found on the Twilio dashboard

  • 🇮🇳India SenthilMohith Chennai

    shashank5563,

    Still we are able to get this error "[HTTP 401] Unable to create record: Authentication Error - invalid username", if the Key module is installed. In the Twilio Settings admin form (/admin/config/system/twilio), Twilio Account SID and Twilio authentication token information stored as a key. Due to this valid SID and Token not passed correctly via Twilio REST Client.

    File: /twilio/src/Form/TwilioAdminForm.php
    Line no: 94

        $key_exists = $this->moduleHandler->moduleExists('key');
    
        if ($key_exists) {
          $form['account'] = [
            '#type' => 'key_select',
            '#required' => TRUE,
            '#default_value' => $config->get('account'),
            '#title' => $this->t('Twilio Account SID'),
          ];
          $form['token'] = [
            '#type' => 'key_select',
            '#required' => TRUE,
            '#default_value' => $config->get('token'),
            '#title' => $this->t('Twilio authentication token'),
          ];
        }
    

    Proposed solution: We should get the valid SID and Token from the selected keys.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India SenthilMohith Chennai

    @shashank5563,

    Created a patch to get the Valid SID and token from the key configurations. Kindly validate from your end and confirm.

  • 🇮🇳India nanny1979

    This patch resolved the issue

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India nanny1979

    Reviewed the patch provided in #6 and I am able to test the SMS successfully as expected

  • Status changed to Fixed over 1 year ago
  • Status changed to Fixed over 1 year ago
Production build 0.71.5 2024