OTPAuth (OTPAuth v0.1.1)

Copy Markdown View Source

This module decodes otpauth://totp/… URIs and extract the various fields.

Once the secret is extracted, it can be used with the NimbleTOTP library to generate the current secret.

Summary

Functions

Extract the secret and label from an otpauth URI, as well as the extra properties.

Functions

decompose_uri(uri)

@spec decompose_uri(String.t()) :: {:ok, binary(), String.t(), map()} | :error

Extract the secret and label from an otpauth URI, as well as the extra properties.

The issuer will be extracted either from the label prefix or from the extra URI parameter. If both are present, they have to be equal or an error will be returned. Returns :error for invalid input.

Examples

iex> OTPAuth.decompose_uri("otpauth://totp/Acme:alice?secret=MFRGGZA&issuer=Acme")
{:ok, "abcd", "alice", %{"issuer" => "Acme"}}

iex> OTPAuth.decompose_uri("otpauth://totp/Acme:alice?secret=INVALID!&issuer=Acme")
:error