Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong validation on accountSid when using API Sid/Api Key to initialize the client #600

Closed
vence722 opened this issue Aug 3, 2020 · 6 comments
Labels
type: twilio enhancement feature request on Twilio's roadmap

Comments

@vence722
Copy link

vence722 commented Aug 3, 2020

Issue Summary

When initialize the client using API Sid/Key, validation still applied to the username field which will check if the field starts with 'AC'. But API Sid should start with 'SK'.

Steps to Reproduce

Initialize the twilio SDK client using API Sid/Key

Code Snippet

import twilio from 'twilio'
twilio(apiSid, apiKey)

Exception/Log

Error: accountSid must start with AC
    at new Twilio (/var/task/node_modules/twilio/lib/rest/Twilio.js:137:11)
    at Object.initializer [as default] (/var/task/node_modules/twilio/lib/index.js:9:10)
    at new Twilio (/var/task/src/services/twilio.js:9:39)
    at initTwilio (/var/task/src/controllers/sms.js:19:16)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.sendVerification (/var/task/src/controllers/sms.js:49:28)

Technical details:

  • twilio-node version: 3.48.0
  • node version: 13.12.0
@childish-sambino
Copy link
Contributor

This is similar to twilio/twilio-csharp#531, but the Node lib is also expecting an account SID in this case.

The fix is to include the account SID in optional params. E.g.:

twilio(apiSid, apiKey, { accountSid });

@childish-sambino childish-sambino added status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started labels Aug 3, 2020
@vence722
Copy link
Author

@childish-sambino Yes, this is my work-around too. I can even use a dummy value of accountSid to bypass the validation. E.g.:

twilio(apiSid, apiKey, { accountSid: 'AC' })

However, I still get a feeling that this is a bug in the twilio node library, as the document mentions that twilio() function could accept both accountSid/accountSecret and apiSid/apiKey pairs. Hope this could get fixed in the future version. Thank you!

@childish-sambino
Copy link
Contributor

Probably need a similar implementation here as twilio/twilio-csharp#533

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@childish-sambino childish-sambino added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap and removed status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started labels Aug 14, 2020
@ducsuus
Copy link

ducsuus commented Dec 16, 2020

I believe this is an important issue to address, even if just to update the error message thrown to explain the different requirements for API Keys.

At present, I understand that this behaviour is not described in the documentation. Because the error thrown suggests that API Keys cannot be used instead of account auth tokens, developers are encouraged to avoid using API Keys, which is poor practice.

If the account SID begins with "SK", a different error message could be provided:

accountSid must start with AC. The SID provided indicates an API Key, which requires the accountSid to be passed as one of the options in the third parameter: {accountSid: "ACXXX}

@jlcaicedo
Copy link

The solution is very easy, when you should use the Account SID you would verify this account start by AC

@childish-sambino childish-sambino added type: twilio enhancement feature request on Twilio's roadmap status: work in progress Twilio or the community is in the process of implementing and removed type: community enhancement feature request not on Twilio's roadmap status: help wanted requesting help from the community labels Nov 23, 2022
childish-sambino pushed a commit that referenced this issue Nov 28, 2022
To better illustrate that an Account SID is required when using an API key to init the client.

Fixes #600
@childish-sambino childish-sambino removed the status: work in progress Twilio or the community is in the process of implementing label Nov 28, 2022
@childish-sambino
Copy link
Contributor

Fixed by #828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants