PasswordlessAuth v0.1.1 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 Functions

Link to this function create_and_send_verification_code(phone_number, opts \\ []) View Source
create_and_send_verification_code(String.t(), list()) ::
  {:ok, map()} | {:error, String.t()}

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 message
  • opts: 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}.

Link to this function remove_code(phone_number) View Source
remove_code(String.t()) ::
  {:ok, %PasswordlessAuth.VerificationCode{code: term(), expires: term()}}
  | {:error, atom()}

Removes a code from state based on the given phone_number

Returns {:ok, %VerificationCode{...}} or {:error, :reason}.

Link to this function verify_code(phone_number, verification_code) View Source
verify_code(String.t(), String.t()) :: boolean()

Verifies that a the given phone_number has the given verification_code stores in state and that the verification code hasn’t expired.

Returns true or false.

Examples

iex> PasswordlessAuth.verify_code("+447123456789", "123456")
false