FusionAuth.TwoFactor (FusionAuth v0.3.0) View Source

The FusionAuth.TwoFactor module provides access functions to the Two Factor APIs.

All functions require a Tesla Client struct created with FusionAuth.client(base_url, api_key, tenant_id).

Link to this section Summary

Functions

Enable Two Factor Authentication by JWT

Enable Two Factor Authentication by User Id

Generate a Two Factor Secret

Generate a Two Factor Secret by JWT

Send a Two Factor code to an authenticated User using a JWT

Send a Two Factor code to an existing User by Id

Send a Two Factor code to complete Two Factor Login

Link to this section Types

Specs

client() :: FusionAuth.client()

Specs

code() :: String.t()

Specs

delivery() :: String.t()

Specs

mobile_phone() :: String.t()

Specs

result() :: FusionAuth.result()

Specs

secret() :: String.t()

Specs

token() :: String.t()

Specs

two_factor_id() :: String.t()

Specs

user_id() :: String.t()

Link to this section Functions

Link to this function

disable_two_factor_by_jwt(client, token, code)

View Source

Specs

disable_two_factor_by_jwt(client(), token(), code()) :: result()

Disable Two Factor by JWT

Examples

iex> client = FusionAuth.client()
iex> token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTIwMDI4MTQsImlhdCI6MTU5MTk5OTIxNCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJSRUZSRVNIX1RPS0VOIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJyb2xlcyI6W119.6hqLDc7-PxHpQRjsdDVt0NcDLcs6ZcoUy5hbwSzMcLM"
iex> FusionAuth.TwoFactor.disable_two_factor_by_jwt(client, token, code)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Disable Two Factor.

Link to this function

disable_two_factor_by_user_id(client, user_id, code)

View Source

Specs

disable_two_factor_by_user_id(client(), user_id(), code()) :: result()

Disable Two Factor by User Id

This API is used to disable Two Factor authentication for a single User. To use this API the User must provide a valid Two Factor verification code.

If the User has configured TextMessage delivery, you may use the Two Factor Send API to deliver a code to the User, the User will then provide this code as input.

Examples

iex> client = FusionAuth.client()
iex> user_id = "fffc8648-bab2-4bdd-b2eb-a48e853d9217"
iex> FusionAuth.TwoFactor.generate_secret(client)
{
  :ok,
  %{
    "secret" => "EgLthMnIgHaQot7sgloI",
    "secretBase32Encoded" => "CIBO3BGJZCAHNEFC33WIEWQI"
  },
  %Tesla.Env{...}
}
iex> FusionAuth.TwoFactor.disable_two_factor_by_user_id(client, user_id, code)
{
  :ok,
  "",
  %Tesla.Env{...}
}
iex> secret = "EgLthMnIgHaQot7sgloI"
iex> FusionAuth.TwoFactor.send_two_factor_code_by_user_id(client, user_id, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}
iex> code = "284703"
iex> FusionAuth.TwoFactor.disable_two_factor_by_user_id(client, user_id, code)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Disable Two Factor.

Link to this function

enable_two_factor_by_jwt(client, token, code, delivery, secret)

View Source

Specs

enable_two_factor_by_jwt(client(), token(), code(), delivery(), secret()) ::
  result()

Enable Two Factor Authentication by JWT

Examples

iex> client = FusionAuth.client()
iex> token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTIwMDI4MTQsImlhdCI6MTU5MTk5OTIxNCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJSRUZSRVNIX1RPS0VOIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJyb2xlcyI6W119.6hqLDc7-PxHpQRjsdDVt0NcDLcs6ZcoUy5hbwSzMcLM"
iex> delivery = "TextMessage"
iex> mobile_phone = "9516401023"
iex> FusionAuth.TwoFactor.generate_secret_for_jwt(client, token)
{
  :ok,
  %{
    "secret" => "S847HD/Gl5zcCf79iI3T",
    "secretBase32Encoded" => "JPHDWHB7Y2LZZXAJ736YRDOT"
  },
  %Tesla.Env{...}
}
iex> secret = "S847HD/Gl5zcCf79iI3T"
iex> FusionAuth.TwoFactor.send_two_factor_code_to_mobile_phone(client, mobile_phone, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}
iex> code = "059984"
iex> FusionAuth.TwoFactor.enable_two_factor_by_jwt(client, token, code, delivery, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Enable Two Factor.

Link to this function

enable_two_factor_by_user_id(client, user_id, code, delivery, secret)

View Source

Specs

enable_two_factor_by_user_id(client(), user_id(), code(), delivery(), secret()) ::
  result()

Enable Two Factor Authentication by User Id

This API is used to enable Two Factor authentication for a single User. To use this API the User must provide a valid Two Factor verification code.

To enable using TextMessage delivery, you may use the Two Factor Send API to deliver a code to the User, the User will then provide this code as input.

Examples

iex> client = FusionAuth.client()
iex> token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTIwMDI4MTQsImlhdCI6MTU5MTk5OTIxNCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJSRUZSRVNIX1RPS0VOIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJyb2xlcyI6W119.6hqLDc7-PxHpQRjsdDVt0NcDLcs6ZcoUy5hbwSzMcLM"
iex> delivery = "TextMessage"
iex> mobile_phone = "9516401023"
iex> FusionAuth.TwoFactor.generate_secret_for_jwt(client, token)
{
  :ok,
  %{
    "secret" => "SP2m6K2Dg/x2JN9DyQvZ",
    "secretBase32Encoded" => "JD62N2FNQOB7Y5RE35B4SC6Z"
  },
  %Tesla.Env{...}
}
iex> secret = "SP2m6K2Dg/x2JN9DyQvZ"
iex> FusionAuth.TwoFactor.send_two_factor_code_to_mobile_phone(client, mobile_phone, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}
iex> code = "819169"
iex> FusionAuth.TwoFactor.enable_two_factor_by_user_id(client, user_id, code, delivery, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Enable Two Factor.

Specs

generate_secret(client()) :: result()

Generate a Two Factor Secret

This API is used to generate a new Two Factor secret for use when enabling Two Factor authentication for a User. This is provided as a helper to assist you in enabling Two Factor authentication.

If this secret will be used with a QR code to allow the User to scan the value it will need utilize the Base32 encoded value returned in the response.

Examples

iex> client = FusionAuth.client()
iex> FusionAuth.TwoFactor.generate_secret(client)
{
  :ok,
  %{
    "secret" => "D90sYs5aPN51Z+ubdQt7",
    "secretBase32Encoded" => "B7OSYYWOLI6N45LH5ONXKC33"
  },
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.

Link to this function

generate_secret_for_jwt(client, token)

View Source

Specs

generate_secret_for_jwt(client(), token()) :: result()

Generate a Two Factor Secret by JWT

Examples

iex> client = FusionAuth.client()
iex> token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTE5OTY1NzAsImlhdCI6MTU5MTk5Mjk3MCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJQQVNTV09SRCIsImVtYWlsIjoiYWRlbGFjcnV6QGNvZ2lsaXR5LmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhcHBsaWNhdGlvbklkIjoiZjdhNzJhZDEtZGU2YS00MTJmLWEzNzItZTY4OWEzYjdhZGNiIiwicm9sZXMiOltdfQ.CqKgxZvqCLPgdT8vSk_KvfNbISe-uIAfQJp0xKWbKno"
iex> FusionAuth.TwoFactor.generate_secret_for_jwt(client, token)
{
  :ok,
  %{
    "secret" => "ZlaRg5hfQ5/cF25tYHKU",
    "secretBase32Encoded" => "MZLJDA4YL5BZ7XAXNZWWA4UU"
  },
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.

Link to this function

send_two_factor_code_by_jwt(client, token)

View Source

Specs

send_two_factor_code_by_jwt(client(), token()) :: result()

Send a Two Factor code to an authenticated User using a JWT

This request is intended to be used to send a Two Factor code to a User that already has enabled Two Factor authentication to assist in disabling Two Factor authentication. When using JWT authentication the User’s Id is retrieved from the JWT. The User must already have Two Factor enabled and have a valid mobile phone for this to succeed.

Examples

iex(137)> token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTIwMDI4MTQsImlhdCI6MTU5MTk5OTIxNCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJSRUZSRVNIX1RPS0VOIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJyb2xlcyI6W119.6hqLDc7-PxHpQRjsdDVt0NcDLcs6ZcoUy5hbwSzMcLM"
iex(138)> FusionAuth.TwoFactor.send_two_factor_code_by_jwt(client, token)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.

Link to this function

send_two_factor_code_by_user_id(client, user_id)

View Source

Specs

send_two_factor_code_by_user_id(client(), user_id()) :: result()

Send a Two Factor code to an existing User by Id

This API is used to send a Two Factor verification code to a User. This may be useful during Two Factor authentication if the initial code is no longer valid. It may be also used to send a code to a User to assist in enabling or disabling Two Factor authentication.

To send a code to a User that already has Two Factor enabled, it is not required they have TextMessage set as their preferred delivery. As long as the User has a mobile phone defined you may send the User a code.

This API requires that the Twilio integration is enabled and configured properly.

This request is intended to be used to send a Two Factor code to a User that already has enabled Two Factor authentication to assist in disabling Two Factor authentication. The User must already have Two Factor enabled and have a valid mobile phone for this to succeed.

Examples

iex> client = FusionAuth.client()
iex> user_id = "fffc8648-bab2-4bdd-b2eb-a48e853d9217"
iex> FusionAuth.TwoFactor.send_two_factor_code_by_user_id(client, user_id)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.

Link to this function

send_two_factor_code_to_complete_login(client, two_factor_id)

View Source

Specs

send_two_factor_code_to_complete_login(client(), two_factor_id()) :: result()

Send a Two Factor code to complete Two Factor Login

This request is intended to send additional messages to the User’s mobile phone during login.

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.

Link to this function

send_two_factor_code_to_mobile_phone(client, mobile_phone, secret)

View Source

Specs

send_two_factor_code_to_mobile_phone(client(), mobile_phone(), secret()) ::
  result()

Send a Two Factor code to a mobile phone

This request is intended to be used to send a Two Factor code to a User to assist in enabling Two Factor authentication

Examples

iex> secret = "D90sYs5aPN51Z+ubdQt7"
iex> mobile_phone= "2015970074"
iex> FusionAuth.TwoFactor.send_two_factor_code_to_mobile_phone(client, mobile_phone, secret)
{
  :ok,
  "",
  %Tesla.Env{...}
}

For more information, visit the FusionAuth API Documentation for Send a Two Factor Code.