xddesigners / otp-authenticator
用于与 silverstripe/mfa 一起使用的 OTP 验证器
1.0.3
2022-04-13 14:25 UTC
Requires
- php: ^7.4 || ^8.0
- giggsey/libphonenumber-for-php: ^8.12
- silverstripe/mfa: ^4.0
- spomky-labs/otphp: ^10
- twilio/sdk: ^6.35
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-09-13 19:35:40 UTC
README
使用一次性密码登录 SilverStripe
您可以配置提供商通过短信或电子邮件发送。
此模块提供了一种验证器,可以连接到 silverstripe/mfa 模块。
此模块默认提供的提供商
需求
- PHP ^7.4
- SilverStripe ^4.1
- silverstripe/mfa: ^4.0
- twilio/sdk: "^6.35"
- giggsey/libphonenumber-for-php: "^8.12"
安装
使用 Composer 安装
composer require xddesigners/otp-authenticator
默认情况下已配置电子邮件提供商,无需进一步设置。
如果您想更改提供商,例如更改为 SMSTools,您可以在 .yml 配置文件中添加以下内容
SilverStripe\Core\Injector\Injector: XD\OTPAuthenticator\Providers\SendProvider: class: XD\OTPAuthenticator\Providers\SMSToolsProvider # The other providers: # class: XD\OTPAuthenticator\Providers\EmailProvider # class: XD\OTPAuthenticator\Providers\TwilioProvider
对于 Twillio 和 SMSTools,您需要在您的环境中定义认证令牌
# Twilio API credentials # (find here https://www.twilio.com/console) TWILIO_ACCOUNT_SID="SID" TWILIO_AUTH_TOKEN="TOKEN" TWILIO_PHONE_NUMBER="PHONE NUMBER" # SMS Tools credentials SMS_TOOLS_CLIENT_ID="CLIENT_ID" SMS_TOOLS_CLIENT_SECRET="CLIENT_SECRET"
输入现有的发送地址
这可以是一个现有的电话号码,如果您使用电子邮件提供商,则是一个现有的电子邮件地址。在成员中添加方法 otpSendTo
,该方法返回一个 OTPSendTo
对象。附加数据可以由配置的提供商用于验证,并存储在 RegisteredMethod
上。短信提供商使用额外的 region
属性来验证电话号码等。
public function otpSendTo() { return new OTPSendTo($member->Email, ['additional' => 'data']); }
创建自定义发送提供商
如果您想使用不同的服务传递代码,可以创建一个自定义提供商。您需要扩展抽象类 SendProvider
并实现所需的方法。
class MySendProvider extends XD\OTPAuthenticator\Providers\SendProvider { /** * Send the code */ public function send($code, $to): bool {} /** * Validate the send to address */ public function validate($to, $data): bool {} /** * Add a regex to validate the input on the frond end */ public function getFieldValidate(): string {} /** * method to check if the provider is properly set up */ public function enabled(): bool {} /** * Obfuscate the sent to address. * So a user has a way to verify the sent address is correct * but in a way an unallowed user couldn't make out the complete address */ public function obfuscateTo($to): string {} /** * Register the field type to switch to. * Accepts phone, email, or text */ public function getFieldType(): string {} /** * Register the field label */ public function getFieldLabel(): string {} }