Generates standard Key URI Format (otpauth://) provisioning URIs for TOTP
and HOTP authenticator apps (Google Authenticator, 1Password, Authy, etc.),
as well as the legacy Google Charts QR URL compatible with nio_google_authenticator.
Summary
Functions
Generates a standard otpauth://hotp/... provisioning URI.
Generates the Google Charts QR code URL in the exact format produced by
nio_google_authenticator.
Generates a standard otpauth://totp/... provisioning URI.
Types
@type hotp_option() :: {:issuer, binary() | nil} | {:algorithm, :sha | :sha1 | :sha256 | :sha512} | {:digest_method, :sha | :sha1 | :sha256 | :sha512} | {:digits, pos_integer()} | {:token_length, pos_integer()}
@type totp_option() :: {:issuer, binary() | nil} | {:algorithm, :sha | :sha1 | :sha256 | :sha512} | {:digest_method, :sha | :sha1 | :sha256 | :sha512} | {:digits, pos_integer()} | {:token_length, pos_integer()} | {:period, pos_integer()} | {:interval_length, pos_integer()}
Functions
@spec hotp(binary(), binary(), non_neg_integer(), [hotp_option()]) :: binary()
Generates a standard otpauth://hotp/... provisioning URI.
Options
:issuer- provider or service name:algorithm(alias:digest_method) -:sha(:sha1),:sha256, or:sha512:digits(alias:token_length) - number of digits (included when not6)
Generates the Google Charts QR code URL in the exact format produced by
nio_google_authenticator.
Note: Google deprecated the
chart.googleapis.comQR endpoint. For new applications, preferEx2FA.otpauth_uri/3paired with a local QR code library such aseqrcode.
@spec totp(binary(), binary(), [totp_option()]) :: binary()
Generates a standard otpauth://totp/... provisioning URI.
Options
:issuer- provider or service name (defaults to configured:issuerif omitted):algorithm(alias:digest_method) -:sha(:sha1),:sha256, or:sha512(included in URI when set to a non-default algorithm):digits(alias:token_length) - number of digits (included when not6):period(alias:interval_length) - time step in seconds (included when not30)
Examples
iex> Ex2FA.URI.totp("JBSWY3DPEHPK3PXP", "alice@example.com", issuer: "MyApp")
"otpauth://totp/MyApp:alice%40example.com?secret=JBSWY3DPEHPK3PXP&issuer=MyApp"