PasswordlessAuth v0.2.0 PasswordlessAuth View Source
PasswordlessAuth is a library gives you the ability to verify a user's phone number by sending them a verification code, and verifying that the code they provide matches the code that was sent to their phone number.
Verification codes are stored in an Agent along with the phone number they were sent to. They are stored with an expiration date/time.
A garbage collector removes expires verification codes from the store. See PasswordlessAuth.GarbageCollector
Link to this section Summary
Functions
Send an SMS with a verification code to the given phone_number
Removes a code from state based on the given phone_number
Verifies that a the given phone_number has the
given verification_code stores in state and that
the verification code hasn't expired
Link to this section Types
verification_failed_reason()
View Source
verification_failed_reason() ::
:attempt_blocked | :code_expired | :does_not_exist | :incorrect_code
verification_failed_reason() :: :attempt_blocked | :code_expired | :does_not_exist | :incorrect_code
Link to this section Functions
create_and_send_verification_code(phone_number, opts \\ []) View Source
Send an SMS with a verification code to the given phone_number
The verification code is valid for the number of seconds given to the
verification_code_ttl config option (defaults to 300)
Options for the Twilio request can be passed to opts[:twilio_request_options.
You'll need to pass at least a from or messaging_service_sid option
to options[:twilio_request_options] for messages to be sent
(see the Twilio API documentation)
For example:
Arguments:
phone_number: The phone number that will receive the text messageopts: Options (see below)
Options:
message: A custom text message template. The verification code can be injected with this formatting: "Yarrr, {{code}} be the secret". Defaults to "Your verification code is: {{code}}"code_length: Length of the verification code (defaults to 6)twilio_request_options: A map of options that are passed to the Twilio request (see the Twilio API documentation)
Returns {:ok, twilio_response} or {:error, error}.
remove_code(phone_number)
View Source
remove_code(String.t()) ::
{:ok, PasswordlessAuth.VerificationCode.t()} | {:error, :does_not_exist}
remove_code(String.t()) :: {:ok, PasswordlessAuth.VerificationCode.t()} | {:error, :does_not_exist}
Removes a code from state based on the given phone_number
Returns {:ok, %VerificationCode{...}} or {:error, :reason}.
verify_code(phone_number, attempt_code)
View Source
verify_code(String.t(), String.t()) ::
:ok | {:error, verification_failed_reason()}
verify_code(String.t(), String.t()) :: :ok | {:error, verification_failed_reason()}
Verifies that a the given phone_number has the
given verification_code stores in state and that
the verification code hasn't expired.
Returns :ok or {:error, :reason}.
Examples
iex> PasswordlessAuth.verify_code("+447123456789", "123456")
{:error, :does_not_exist}