Table of Contents

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

httpClient HttpClient

Client used to call the Verify API.

options IOptions<TwilioVerifyOptions>

Verify configuration.

logger ILogger<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

phoneNumber string

The number in E.164 form, as it was given to StartAsync(string, PhoneVerificationChannelType, string?, CancellationToken).

code string

What the person typed.

cancellationToken CancellationToken

Token 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

phoneNumber string

The number in E.164 form.

channel PhoneVerificationChannelType

How the code reaches the person. Defaults to a text message.

locale string

The language of the message, as an IETF tag (pt-BR, en), or null for the provider's choice.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<PhoneVerification>

Whether the code was sent, and why not when it was not.