You are here

public static function TwilioValidation::validateIncoming in Twilio SMS Integration 8

Validate an incoming message using Twilio SDK

Parameters

\Symfony\Component\HttpFoundation\Request $request The request object.:

\Drupal\Component\Plugin\ConfigurablePluginInterface The Twilio plugin.:

Return value

boolean TRUE if the request validates, FALSE if not.

See also

https://www.twilio.com/docs/api/security

1 call to TwilioValidation::validateIncoming()
Twilio::buildIncomingFromRequest in src/Plugin/SmsGateway/Twilio.php
Validates the webhook request and creates an SMS message object.

File

src/Utility/TwilioValidation.php, line 28

Class

TwilioValidation
Class TwilioValidation

Namespace

Drupal\sms_twilio\Utility

Code

public static function validateIncoming(Request $request, SmsGatewayPluginInterface $sms_gateway) {
  $url = Url::fromRoute('sms.incoming.receive.' . $sms_gateway
    ->getPluginId())
    ->setAbsolute()
    ->toString();
  $signature = $request->headers
    ->get('x-twilio-signature');
  $token = $sms_gateway
    ->getConfiguration()['auth_token'];
  $validator = new RequestValidator($token);
  return $validator
    ->validate($signature, $url, $request->request
    ->all());
}