Appearance
SMS Framework provides a system for determining whether a phone number has been verified.
Verification typically happens by sending a message containing a code to a phone number. The recipient of the message then has a fixed amount of time to claim the code by entering the code into a form.
Verification Configuration
Verification can be configured by the sms.verification
service parameter.
yaml
sms.verification:
# Disabling verification will remove associated services.
enabled: true
route:
path: '/verify'
success: '/user'
# Whether to enforce unique phone numbers. If a newly verified phone number
# also exists on another account, the phone number verification will be
# deleted. If unverified.purge_fields is true, field data will be purged.
unique: true
unverified:
lifetime: 900
# Phone number data may not necessarily come from fields, but fields will be checked for this data.
purge_fields: true
message: |-
Your verification code is '[sms-message:verification-code]'.
Go to [sms:verification-url] to verify your phone number.
- [site:name]
Keys
enabled
: Verification is activated when set to true. When this is false, the verification service (\Drupal\sms\PhoneNumberVerification\SmsPhoneNumberVerificationInterface
) and routes are no longer available.route.path
: mapping for the verification route.route.success
: the path to send the user after successful verification.unique
: when true, allows only one verification per phone number. This will delete verifications for a phone number when a new one is created.unverified.lifetime
: How long in seconds a verification can be unverified for, before it can no longer be claimed, and the verification is marked for deletion.unverified.purge_fields
: Whether phone number field data should be removed, and entity resaved, if a verification expires.message
— the contents of the SMS verification message. Tokens include[sms-message:verification-code]
and[sms:verification-url]
for the verification code and verification URL respectively.
Verification SMS
When phone number field mapping is used with the verification
flag, a verification SMS message will automatically be sent to a phone when the phone number is saved to an entity.
Verification Field Widget
The SMS Framework Phone Verification
field widget may be used with a telephone field to show verification status of the value associated with the widget. The widget can also lock modifications to the value if a verification message was dispatch recently.
Verification form
When a verification code is received, it may be entered into the verify form to complete verification.
A code must be entered before it expires.
Programmatic use
You can also use verification services manually, instead of relying on hooks to send verification messages, cron to clean up messages, and the verification form to verify messages:
Create verification and send a verification message
SmsPhoneNumberVerificationInterface::newPhoneVerification
can be used to create a verification record with random code and send a verification SMS.
Determine if a entity/object and phone number combination is verified
SmsPhoneNumberVerificationInterface::isVerified
Determine if a verification exists which has not been claimed
SmsPhoneNumberVerificationInterface::claimableVerificationByCodeExists
Verifies a phone number for an entity/object
SmsPhoneNumberVerificationInterface::verify
An exception (\Drupal\sms\PhoneNumberVerification\Exception\NoPhoneNumberVerificationExists
) is thrown if a verification does not exist with the provided context.
Verifies a phone number by code
SmsPhoneNumberVerificationInterface::verifyByCode
Completes verification process of any verification with the provided code.
An exception (\Drupal\sms\PhoneNumberVerification\Exception\NoPhoneNumberVerificationExists
) is thrown if a verification does not exist with the provided context.
Delete any verifications for a entity/object
SmsPhoneNumberVerificationInterface::deletePhoneVerifications