Configuration

Enable OTP codes and run php artisan admin:migrate. It creates the tables of the OTP codes and the whitelisted accounts.
config/admin_helpers.php
Use 'chars' => 0, 'numbers' => 5 for a numeric code. Codes are not case sensitive.

Channels

The verificator request parameter selects where the code is sent: The default is the AUTH_VERIFICATOR environment variable, or email. When a user without a phone asks for an SMS code, the code is sent by e-mail.

OTP response

Routes which send a code return its details in the otp store:
  • format describes the code: x is a letter, 0 a number. Use it for the input mask of the app.
  • identifier is masked, e.g. j***@e***m, when the code was resent to another channel of a signed in user.
  • token contains the code only for test identifiers.
  • verified: true means no code was sent, because the e-mail or phone is already verified.

Routes

AdminAuth::otp() registers: Send another verificator to auth/otp/resend to switch the channel, e.g. from e-mail to SMS. For a registered user, the code goes to the e-mail or phone stored in the database, not to the request value.

SMS codes

Codes for phone numbers are sent through SmartSMS by AdminHelpers\Sms\SmartSms. Set the credentials in .env:
.env
  • SMARTSMS_PASSWORD_MD5 can hold the MD5 hash of the password instead of SMARTSMS_PASSWORD.
  • With SMARTSMS_TEST=true, the default, messages are only written to the log: the sms log channel when it exists, otherwise single.
  • A config/smartsms.php file with the keys username, password, from, test and log_channel replaces the values from .env.
The package also registers the sms notification channel. It sends the toSms($notifiable) text of a notification to routeNotificationForSms() of the notifiable, or to its phone attribute. The SMS login verification of the administration uses this channel.
app/Notifications/OrderShipped.php

Testing

Test identifiers receive no e-mail or SMS. The response returns the code in otp.token instead.
config/admin_helpers.php
Test identifiers also accept every code of whitelisted_tokens, so testers can use a fixed code:
config/admin_helpers.php

Debug mode

With AUTH_TOKEN_DEBUG=true, every e-mail and phone is a test identifier. Debug mode works only when APP_DEBUG is enabled and the environment is local or stagging.
.env
The test environment is stagging, spelled with two g’s. An environment named staging is treated as production.

Whitelisted accounts

The Allowed OTP e-mails module in the Settings group of the administration turns real codes off for an e-mail or phone for 15 minutes. Use it for app store reviewers or for support. During that time, the account accepts the codes of whitelisted_tokens.

Custom OTP model

Extend the OTP model to change how codes are generated or sent. Keep its table:
app/Models/Auth/OtpToken.php
Delete expired codes with php artisan otp:clean. The command is not scheduled automatically.
E-mail with an OTP code