# `OTPAuth`
[🔗](https://github.com/evenfurther/otpauth/blob/main/lib/otpauth.ex#L1)

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

Once the secret is extracted, it can be used with the
[NimbleTOTP](https://hex.pm/packages/nimble_totp) library to generate the current secret.

# `decompose_uri`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
