ferdousulhaque / laravel-otp-validate

Laravel package for OTP validation with built-in features like max retry and resend mechanism. Both OTP/Security Code over SMS or Email or AWS SNS of your choice with template user-defined.
71 stars 13 forks source link

Set SMS type to Transactional via `MessageAttributes` when using AWS SNS #8

Closed alex-ng-wesoft closed 2 years ago

alex-ng-wesoft commented 2 years ago

... instead of using a SetSMSAttributes request.

While globally setting the default SMS type via SetSMSAttributes does work most of the time, it has some issues:

  1. It requires an extra IAM permission.
  2. It forces users of the library to use transactional SMSes as the default. This may not be what they want.
  3. Per https://docs.aws.amazon.com/general/latest/gr/sns.html#limits_sns_api_throttles_hard SetSMSAttributes is rate limited to one transaction per second. Rates for sending SMSes via SNS are generally multiple messages per second, so using SetSMSAttributes makes the library less suitable for supporting many users at the same time.
  4. In theory there's a race condition where this library sets the global value to transactional, some other code somewhere sets the global value to promotional immediately after, resulting in an OTP message being sent as promotional.

This commit instead switches to specifying the message type using the AWS.SNS.SMS.SMSType attribute. This avoids all of the issues above while still ensuring OTP messages are sent as transactional.

See https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html#sms_publish_sdk for details.

alex-ng-wesoft commented 2 years ago

Hi @ferdousulhaque: could you take a look at this PR if you have the time? Thanks.

ferdousulhaque commented 2 years ago

Well explained, let me review and merge, thanks 👍