# TotpSecret


```
public interface TotpSecret
```

<br />

*** ** * ** ***

Represents a TOTP secret that is used for enrolling a TOTP second factor. Contains the shared secret key and other parameters to generate time-based one-time passwords. Implements methods to retrieve the shared secret key, generate a QR code URL, and open the QR code URL in an OTP authenticator app.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#generateQrCodeUrl()()` Returns a QR code URL. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#generateQrCodeUrl(java.lang.String,java.lang.String)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html accountName, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html issuer)` Returns a QR code URL. |
| `abstract int` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getCodeIntervalSeconds()()` Returns the interval (in seconds) when the OTP codes should change. |
| `abstract int` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getCodeLength()()` Returns the length of the OTP codes to be generated. |
| `abstract long` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getEnrollmentCompletionDeadline()()` Returns the timestamp (in seconds since epoch) by which enrollment should complete. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getHashAlgorithm()()` Returns the hashing algorithm used to generate time-based one-time passwords. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getSessionInfo()()` Returns the enrollment session. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#getSharedSecretKey()()` Returns the shared secret key/seed used to generate time-based one-time passwords. |
| `abstract void` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#openInOtpApp(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html qrCodeUrl)` Opens the specified QR Code URL in an OTP authenticator app on the device as a new Activity. |
| `abstract void` | `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#openInOtpApp(java.lang.String,java.lang.String,android.app.Activity)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html qrCodeUrl, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html fallbackUrl, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/app/Activity.html activity )` Opens the specified QR Code URL in an OTP app on the device. |

## Public methods

### generateQrCodeUrl

```
abstract @NonNull String generateQrCodeUrl()
```

Returns a QR code URL. For more details, see [Key-Uri-Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format). You can display this URL to the end-user as a QR code to be scanned into an OTP authenticator app, like Google Authenticator. Alternatively, you can automatically load this URL into a TOTP authenticator app using `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#openInOtpApp(java.lang.String)`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | A QR code URL String. |

### generateQrCodeUrl

```
abstract @NonNull String generateQrCodeUrl(@NonNull String accountName, @NonNull String issuer)
```

Returns a QR code URL. For more details, see [Key-Uri-Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format). You can display this URL to the end-user as a QR code to be scanned into an OTP authenticator app, like Google Authenticator. Alternatively, you can automatically load this URL into a TOTP authenticator app using `https://firebase.google.com/docs/reference/android/com/google/firebase/auth/TotpSecret#openInOtpApp(java.lang.String)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html accountName` | the name of the account/app along with a user identifier.. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html issuer` | issuer of the TOTP (the app name). |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | A QR code URL String. |

### getCodeIntervalSeconds

```
abstract int getCodeIntervalSeconds()
```

Returns the interval (in seconds) when the OTP codes should change.

| Returns |
|---|---|
| `int` | The interval (in seconds) when the OTP codes should change. |

### getCodeLength

```
abstract int getCodeLength()
```

Returns the length of the OTP codes to be generated.

| Returns |
|---|---|
| `int` | Length of the one-time passwords to be generated. |

### getEnrollmentCompletionDeadline

```
abstract long getEnrollmentCompletionDeadline()
```

Returns the timestamp (in seconds since epoch) by which enrollment should complete.

| Returns |
|---|---|
| `long` | The timestamp (in seconds since epoch) by which enrollment should complete. |

### getHashAlgorithm

```
abstract @NonNull String getHashAlgorithm()
```

Returns the hashing algorithm used to generate time-based one-time passwords.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | Hashing algorithm used. |

### getSessionInfo

```
abstract @NonNull String getSessionInfo()
```

Returns the enrollment session.

### getSharedSecretKey

```
abstract @NonNull String getSharedSecretKey()
```

Returns the shared secret key/seed used to generate time-based one-time passwords.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | Shared secret key for enrolling in TOTP MFA. |

### openInOtpApp

```
abstract void openInOtpApp(@NonNull String qrCodeUrl)
```

Opens the specified QR Code URL in an OTP authenticator app on the device as a new Activity. The shared secret key and account name will be populated in the OTP authenticator app. The URL uses the `otpauth://` scheme and will be opened on an app that handles this scheme, if it exists on the device.

If a suitable OTP authenticator app was not found, this opens the Google Play Store instead, using the following URL: `https://play.google.com/store/search?q=otpauth&amp;c=apps`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html qrCodeUrl` | the QR Code URL to open. |

### openInOtpApp

```
abstract void openInOtpApp(
    @NonNull String qrCodeUrl,
    @NonNull String fallbackUrl,
    @NonNull Activity activity
)
```

Opens the specified QR Code URL in an OTP app on the device. The shared secret key and account name will be populated in the OTP app. The URL uses the `otpauth://` scheme and will be opened on an app that handles this scheme, if it exists on the device.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html qrCodeUrl` | the QR Code URL to open. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html fallbackUrl` | the URL to open if a suitable OTP authenticator app was not found. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/app/Activity.html activity` | a reference to the current activity, to open the OTP authenticator app on. |