View Source MaatFeather.Auth.TOTP (maat_feather v0.2.0)
totp
TOTP
# config/config.exs
config :maat_feather, MaatFeather.Auth.TOTP,
secret_key_size:
if(System.get_env("TOTP_SECRET_KEY_SIZE") != nil,
do: String.to_integer(System.get_env("TOTP_SECRET_KEY_SIZE")),
else: 10
),
iss: System.get_env("AUTH_ISS", "maat_feather")
Link to this section Summary
Functions
Generate a QR code SVG
Generate a new secret key.
Generate a new token based on the secret key.
Verify the token against the secret key.
Link to this section Functions
Generate a QR code SVG
parameters
Parameters
username
: username/email of user.secret_key
: The secret key.
examples
Examples
iex> qrcode_svg = MaatFeather.Auth.TOTP.gen_qrcode!(username/email, secret_key)
"A really bigger qrcode svg here"
@spec gen_secret_key!() :: binary()
Generate a new secret key.
examples
Examples
iex> secret_key = MaatFeather.Auth.TOTP.gen_secret_key!()
<<192, 175, 151, 20, 122, 3, 59, 211, 201, 140>>
Generate a new token based on the secret key.
parameters
Parameters
secret_key
: The secret key.
examples
Examples
iex> token = MaatFeather.Auth.TOTP.gen_token!(secret_key)
"982943"
Verify the token against the secret key.
parameters
Parameters
secret_key
: The secret key.token
: The token.
examples
Examples
iex> is_valid? = MaatFeather.Auth.TOTP.is_valid?(secret_key, valid_token)
true
iex> is_valid? = MaatFeather.Auth.TOTP.is_valid?(secret_key, expired_or_invalid_token)
false