0

I am calling Twilio client to make a phone call and providing To, From and url parameters. I want to set XSRF token as part of the url so that when twilio call the url the token will be validated and my rest api send the twiml expression so that twilio will call other phone number and connect both the calls. Is there any way I can set XSRF token as part of the header. Below is my code.

TwilioRestClient client = new TwilioRestClient(accountSid, authToken);

        Account mainAccount = client.getAccount();
        CallFactory callFactory = mainAccount.getCallFactory();
        Map<String, String> callParams = new HashMap<String, String>();
        callParams.put("To", "+1 xxx-xxx-xxxx");
        callParams.put("From", "+1 xxx-xxx-xxxx");
        callParams.put("X-XSRF-TOKEN", "token");
        callParams.put("Url", "myurl/+1xxx-xxx-xxxx");
        try {
            Call call = callFactory.create(callParams);
        } catch (TwilioRestException e) {
            e.printStackTrace();
        }
laks
  • 11
  • 5
  • My application does token authentication so giving the exception(Error 403 Expected CSRF token not found. Has your session expired?) while accessing my callback rest service to get Twiml expression. Can you please suggest me the best approach to make it work? – laks Jul 12 '16 at 18:29

1 Answers1

0

Twilio evangelist here.

To my knowledge there is no way to pass Twilio an XSRF token that we turn around and hand you back when we make a webhook request to your endpoint.

Instead, maybe look at using Twilios request validation capability to validate that requests coming to that endpoint only come from Twilio:

https://www.twilio.com/docs/api/security#validating-requests

This may allow you to not have to use session validation on that specific endpoint and at the same time prevent random users from making requests to it.

Hope that helps.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32
  • Hi Devin,I have to implement browser to phone functionality in reactjs component. Can you please suggest me what is the best approach? Can I go with the same approach that is mentioned as part of twilio.js functionality? Please respond as soon as possible. Thank you. – laks Jul 15 '16 at 02:56