URI::otpauth(3) User Contributed Perl Documentation URI::otpauth(3)

# [NAME](#NAME)

URI::otpauth - URI scheme for secret keys for OTP secrets. Usually found in QR codes

# [VERSION](#VERSION)

Version 5.29

# [SYNOPSIS](#SYNOPSIS)

```
  use URI;
  # optauth URI from textual uri
  my $uri = URI->new( 'otpauth://totp/Example:alice@google.com?secret=NFZS25DINFZV643VOAZXELLTGNRXEM3UH4&issuer=Example' );
  # same URI but created from arguments
  my $uri = URI::otpauth->new( type => 'totp', issuer => 'Example', account_name => 'alice@google.com', secret => 'is-this_sup3r-s3cr3t?' );
```

# [DESCRIPTION](#DESCRIPTION)

This URI scheme is defined in &lt;https://github.com/google/google-authenticator/wiki/Key-Uri-Format/&gt;:

# [SUBROUTINES/METHODS](#SUBROUTINES/METHODS)

## ["new"](#_new_)

Create a new URI::otpauth. The available arguments are listed below;

- account\_name - this can be the account name (probably an email address) used when authenticating with this secret. It is an optional field.
- algorithm - this is the cryptographic hash function &lt;https://en.wikipedia.org/wiki/Cryptographic\_hash\_function&gt; that should be used. Current values are SHA1 &lt;https://en.wikipedia.org/wiki/SHA-1&gt;, SHA256 &lt;https://en.wikipedia.org/wiki/SHA-2&gt; or SHA512 &lt;https://en.wikipedia.org/wiki/SHA-2&gt;. It is an optional field and will default to SHA1.
- counter - this is only required when the type is HOTP.
- digits - this determines the length &lt;https://github.com/google/google-authenticator/wiki/Key-Uri-Format/#digits&gt; of the code presented to the user. It is an optional field and will default to 6 digits.
- issuer - this can be the application / system &lt;https://github.com/google/google-authenticator/wiki/Key-Uri-Format/#issuer&gt; that this secret can be used to authenticate to. It is an optional field.
- label - this is the issuer and the account name &lt;https://github.com/google/google-authenticator/wiki/Key-Uri-Format/#label&gt; joined with a ":" character. It is an optional field.
- period - this is the period that the TOTP code is valid for &lt;https://github.com/google/google-authenticator/wiki/Key-Uri-Format/#counter&gt;. It is an optional field and will default to 30 seconds.
- secret - this is the key &lt;https://en.wikipedia.org/wiki/Key\_(cryptography)&gt; that the TOTP &lt;https://en.wikipedia.org/wiki/Time-based\_one-time\_password&gt;/HOTP &lt;https://en.wikipedia.org/wiki/HMAC-based\_one-time\_password&gt; algorithm uses to derive the value. It is an arbitrary byte string and must remain private. This field is mandatory.
- type - this can be 'hotp &lt;https://en.wikipedia.org/wiki/HMAC-based\_one-time\_password&gt;' or 'totp &lt;https://en.wikipedia.org/wiki/Time-based\_one-time\_password&gt;'. This field will default to 'totp'.

## ["algorithm"](#_algorithm_)

Get or set the algorithm of this otpauth URI.

## ["account\_name"](#_account_name_)

Get or set the account\_name of this otpauth URI.

## ["counter"](#_counter_)

Get or set the counter of this otpauth URI.

## ["digits"](#_digits_)

Get or set the digits of this otpauth URI.

## ["issuer"](#_issuer_)

Get or set the issuer of this otpauth URI.

## ["label"](#_label_)

Get or set the label of this otpauth URI.

## ["period"](#_period_)

Get or set the period of this otpauth URI.

## ["secret"](#_secret_)

Get or set the secret of this otpauth URI.

## ["type"](#_type_)

Get or set the type of this otpauth URI.

```
  my $type = $uri->type('hotp');
```

# [CONFIGURATION AND ENVIRONMENT](#CONFIGURATION_AND_ENVIRONMENT)

URI::otpauth requires no configuration files or environment variables.

# [DEPENDENCIES](#DEPENDENCIES)

URI

# [DIAGNOSTICS](#DIAGNOSTICS)

"secret is a mandatory parameter for URI::otpauth"

The secret parameter was not detected for the URI::otpauth-&gt;**new()** method.

# [INCOMPATIBILITIES](#INCOMPATIBILITIES)

None reported.

# [BUGS AND LIMITATIONS](#BUGS_AND_LIMITATIONS)

To report a bug, or view the current list of bugs, please visit &lt;https://github.com/libwww-perl/URI/issues&gt;

# [AUTHOR](#AUTHOR)

David Dick "&lt;ddick@cpan.org&gt;"

# [LICENSE AND COPYRIGHT](#LICENSE_AND_COPYRIGHT)

Copyright (c) 2024, David Dick "&lt;ddick@cpan.org&gt;".

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

2026-10-26 perl v5.44.0

---

Document: URI::otpauth(3pm) from perl-uri 5.40-r2 (Chainguard OS)
Source: https://github.com/libwww-perl/URI.git
