throneless-tech / libsignal-service-javascript

A javascript library for basic interaction with the Signal messaging service, adapted from Signal-Desktop.
GNU General Public License v3.0
57 stars 21 forks source link

402 Payment Required on requestSMS #35

Open jaaop opened 3 years ago

jaaop commented 3 years ago

Hi, I'm getting the following when requesting a verification code (tried both on a Twilio US number and my AU number).

code: 402, response: '<html>\n' + '<head>\n' + '<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>\n' + '<title>Error 402 Payment Required</title>\n' + '</head>\n' + '<body><h2>HTTP ERROR 402 Payment Required</h2>\n' + '<table>\n' + '<tr><th>URI:</th><td>/v1/accounts/sms/code/<THE NUMBER></td></tr>\n' + '<tr><th>STATUS:</th><td>402</td></tr>\n' + '<tr><th>MESSAGE:</th><td>Payment Required</td></tr>\n' + '<tr><th>SERVLET:</th><td>jersey</td></tr>\n' + '</table>\n' + '\n' + '</body>\n' + '</html>\n' }

To my understand, the Signal API is free to use. Any idea what could be causing this? Thanks

idifrancesco commented 3 years ago

It happens due to a missed captcha verification.

You have to get a signal captcha token browsing the following link: https://signalcaptchas.org/registration/generate.html After you resolved the captcha you can see the token displayed in the developer console.

Unfortunately a way to send the verification token to signal server isn't implemented yet.

I suggest to apply the following patch, it worked for me:

Replace: https://github.com/throneless-tech/libsignal-service-javascript/blob/18698abee4065cdfbf1aa842c845834e010c7e06/src/WebAPI.js#L619-L625 With:

function requestVerificationSMS(number, token) {
      return _ajax({
        call: 'accounts',
        httpType: 'GET',
        urlParameters: `/sms/code/${number}${token ? `?captcha=${token}` : '' }`,
      });
    }

Replace: https://github.com/throneless-tech/libsignal-service-javascript/blob/18698abee4065cdfbf1aa842c845834e010c7e06/src/AccountManager.js#L48-L50 With:

requestSMSVerification(token) {
    return this.server.requestVerificationSMS(this.username, token);
  }

In the end request sms verification as following:

await accountManager.requestSMSVerification('signal token')