Class TwilioPhoneVerifier
- Namespace
- NuvTools.Security.Verification.Twilio
- Assembly
- NuvTools.Security.Verification.Twilio.dll
Sends and checks one-time codes through Twilio Verify. Twilio generates, delivers and expires the code; the application never holds it.
public sealed class TwilioPhoneVerifier : IPhoneVerifier
- Inheritance
-
TwilioPhoneVerifier
- Implements
- Inherited Members
Constructors
TwilioPhoneVerifier(HttpClient, IOptions<TwilioVerifyOptions>, ILogger<TwilioPhoneVerifier>)
Sends and checks one-time codes through Twilio Verify. Twilio generates, delivers and expires the code; the application never holds it.
public TwilioPhoneVerifier(HttpClient httpClient, IOptions<TwilioVerifyOptions> options, ILogger<TwilioPhoneVerifier> logger)
Parameters
httpClientHttpClientClient used to call the Verify API.
optionsIOptions<TwilioVerifyOptions>Verify configuration.
loggerILogger<TwilioPhoneVerifier>Logger for diagnostics.
Methods
CheckAsync(string, string, CancellationToken)
Checks the code the person typed against the one pending for the number.
public Task<PhoneVerification> CheckAsync(string phoneNumber, string code, CancellationToken cancellationToken = default)
Parameters
phoneNumberstringThe number in E.164 form, as it was given to StartAsync(string, PhoneVerificationChannelType, string?, CancellationToken).
codestringWhat the person typed.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<PhoneVerification>
Succeeded only when the code is the pending one. A code is good once: after a success the number has no code pending.
StartAsync(string, PhoneVerificationChannelType, string?, CancellationToken)
Sends a new code to the number, replacing any code still pending for it.
public Task<PhoneVerification> StartAsync(string phoneNumber, PhoneVerificationChannelType channel = PhoneVerificationChannelType.Sms, string? locale = null, CancellationToken cancellationToken = default)
Parameters
phoneNumberstringThe number in E.164 form.
channelPhoneVerificationChannelTypeHow the code reaches the person. Defaults to a text message.
localestringThe language of the message, as an IETF tag (
pt-BR,en), ornullfor the provider's choice.cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<PhoneVerification>
Whether the code was sent, and why not when it was not.