kamax-matrix / mxisd

Federated Matrix Identity Server
GNU Affero General Public License v3.0
220 stars 112 forks source link

Phone numbers cannot be validated using Twilio #177

Closed jtanveer closed 5 years ago

jtanveer commented 5 years ago

I am trying to validate phone number using Twilio. Currently I am using Twilio trial account to validate phone numbers. But whenever I try to validate phone number from client I get the following response:

May 26 05:37:18 ip-172-31-22-134 mxisd[13574]: [XNIO-1 task-10] INFO io.kamax.mxisd.http.undertow.handler.BasicHttpHandler - Request POST http://127.0.0.1:8090/_matrix/identity/api/v1/validate/msisdn/requestToken - Error M_BAD_REQUEST: Phone numbers cannot be validated at this time. Contact your administrator.

I have tested Twilio API separately. It works fine. I tried to call the above API from PostMan. It returns an sid, but no SMS is sent to the number. I have used to following configuration for Twilio in mxisd.yaml file:

#### SMS Connector
threepid:
  medium:
    msisdn:
      connectors:
        twillo:
          account_sid: 'AC098esd98fsd98wq098fds009sf8dwer'    # not actual value
          auth_token: '1283dsfjfjo23ierjioio23ioufwuei'    # not actual value
          number: '+12345672966'    # not actual value

Please let me know, if I am doing anything wrong here. How can I resolve this issue?

KishCom commented 5 years ago

I am having the exact same issue. I am still waiting for SRV records to propagate - could this be responsible?

maxidorius commented 5 years ago

Please provide all the log lines generated during that call and not just a single log line. Please see the Troubleshooting guide.

jtanveer commented 5 years ago

Hi @maxidorius
Thanks for your prompt response and sorry for not following the troubleshooting guide. I have captured the following logs from syslog:

May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.session.SessionManager - Server 127.0.0.1 is asking to create session for io.kamax.matrix.ThreePid@7ed37b43 (Attempt #0) - Next link: null May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.session.SessionManager - No existing session for io.kamax.matrix.ThreePid@7ed37b43 May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.session.SessionManager - Generated new session 1558929736154 to validate io.kamax.matrix.ThreePid@7ed37b43 from server 127.0.0.1 May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.session.SessionManager - Stored session 1558929736154 May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.session.SessionManager - Session 1558929736154 for io.kamax.matrix.ThreePid@7ed37b43: sending validation notification May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.threepid.generator.GenericTemplateNotificationGenerator - Generating notification content for 3PID Session validation May 27 04:02:16 ip-172-31-22-134 mxisd[18944]: [XNIO-1 task-1] INFO io.kamax.mxisd.http.undertow.handler.BasicHttpHandler - Request POST http://127.0.0.1:8090/_matrix/identity/api/v1/validate/msisdn/requestToken - Error M_BAD_REQUEST: Phone numbers cannot be validated at this time. Contact your administrator.

Please let me know if you need any other information.

KishCom commented 5 years ago

My logs almost match @jtanveer

May 27 07:27:39 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.session.SessionManager - Server 127.0.0.1 is asking to create session for io.kamax.matrix.ThreePid@80115e78 (Attempt #1) - Next link: null
May 27 07:27:39 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.session.SessionManager - No existing session for io.kamax.matrix.ThreePid@80115e78
May 27 07:27:39 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.session.SessionManager - Generated new session 1558956459896 to validate io.kamax.matrix.ThreePid@80115e78 from server 127.0.0.1
May 27 07:27:40 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.session.SessionManager - Stored session 1558956459896
May 27 07:27:40 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.session.SessionManager - Session 1558956459896 for io.kamax.matrix.ThreePid@80115e78: sending validation notification
May 27 07:27:40 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.threepid.generator.GenericTemplateNotificationGenerator - Generating notification content for 3PID Session validation
May 27 07:27:40 superman mxisd[25536]: [XNIO-1 task-2] INFO io.kamax.mxisd.http.undertow.handler.BasicHttpHandler - Request POST http://kish.io/_matrix/identity/api/v1/validate/msisdn/requestToken - Error M_BAD_REQUEST: Phone numbers cannot be validated at this time. Contact your administrator.

Here's my config (with sensitive details blanked)

matrix:
  domain: 'kish.io'
server:
  port: 8299
key:
  path: '/var/lib/mxisd/keys'
storage:
  provider:
    sqlite:
      database: '/var/lib/mxisd/store.db'
synapseSql:
  enabled: true
  type: "postgresql"
  connection: "//databasehost:4567/defaultdb?user=postgresql&password=thisisnotmydatabasebassword"
threepid:
  medium:
  msisdn:
    connectors:
      twilio:
        account_sid: 'thisisnotmyaccountsid'
        auth_token: 'thisisnotmyauthtoken'
        number: '+15555551212'
    email:
      identity:
        from: "matrix-identity@kish.io"
      connectors:
        smtp:
          host: "smtp.mailgun.org"
          tls: 1
          port: 587
          login: "postmaster@kish.io"
          password: "thisisnottherealpassword"
maxidorius commented 5 years ago

@KishCom your configuration indentation is wrong for the msisdn key and its sub-keys.

@jtanveer Please restart mxisd and check that you can find something akin the following lines in the logs right after startup:

[main] INFO io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig - --- Phone SMS Twilio connector config ---
[main] INFO io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig - Account SID: myAccountSid
[main] INFO io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig - Sender number: +123456789
[main] INFO io.kamax.mxisd.threepid.connector.phone.PhoneSmsTwilioConnector - Twilio API has been initiated
jtanveer commented 5 years ago

@maxidorius Sorry for all the troubles! After reevaluating my config file, I found out that there was a spelling mistake in my msisdn configuration. I accidentally wrote twillo instead of twilio! That was really silly from my end. After correcting it, I started to get the above log and SMS is also being sent as expected.

Thank you very much for your support and also for this nice project!