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

Add ability to pass captcha token when requesting SMS verification #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ accountManager.registerSingleDevice("myCode").then(result => {
});
```

##### CAPTCHA challenge requirement
Sometimes the Signal server requires a captcha token for registering a new account. The registration fails with a captcha required error or with `402 Payment Required` error. In this case, you need to solve a CAPTCHA challenge.

To get the token, got to [Captcha generation](https://signalcaptchas.org/registration/generate.html). After filling the captcha, the site doesn't show the token but redirects to a signalcaptcha:// url that contains the token. To see the URL you can open the browser developer tools (F12) before completing the captcha. Check the console/network tab in the developer tools for a redirect starting with `signalcaptcha://`. Everything after `signalcaptcha://` is the captcha token.

You can pass the captcha token to `registerSingleDevice` function like so:
```
const captchaToken = "...";
accountManager.requestSMSVerification(captchaToken).then(result => {
console.log("Sent verification code.");
});
```

Note: Captcha token is valid for only a short period of time.

### Sending messages

To send a message, connect a `MessageSender` instance to the Signal service:
Expand Down
4 changes: 2 additions & 2 deletions src/AccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class AccountManager extends EventTarget {
return this.server.requestVerificationVoice(this.username);
}

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

async encryptDeviceName(name, providedIdentityKey) {
Expand Down
4 changes: 2 additions & 2 deletions src/WebAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,11 @@ function initialize({
});
}

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

Expand Down