Authing DocsDocuments
Concept
workflow
Guides
Development Integration
Application integration
Concept
workflow
Guides
Development Integration
Application integration
Old Version
Development Integration
  • Single Sign-On (SSO)
  • Login component

  • JavaScript/Node.js

  • Java / Kotlin

  • Python

  • C#

  • PHP

  • Go

  • Ruby
  • Android

    • Quick start
    • Hosting page
    • APIs

    • Third-party identity source

    • Scenario

      • Logout
      • Overseas
      • Authing OTP
      • Device management
    • On-premise
    • Android Guard Change log
    • Error code
  • iOS

  • Flutter

  • React Native
  • WeChat Mini Program
  • WeChat webpage authorization
  • Framework Integration
  • Error code
  1. Development Integration
  2. /
  3. Android
  4. /
  5. Scenario
  6. /
  7. Authing OTP

¶ Authing OTP

Update Time: 2025-05-14 08:32:28
Edit

The current OTP SDK we provide supports TOTP(The Time-based One-time Password algorithm), Can be used to Multifactor authentication(MFA) (opens new window) in the OTP authentication method. The SDK can quickly generate the OTP verification code and provide the ability to add, delete, modify, and check. You can also download Authing OTP (opens new window) Experience the official Authing application.

drawing

¶ Data format

The OTP data format is uri, for example:

otpauth://totp/GuardPool:test?secret=E55EYQJ5EUHX6ALB&period=30&digits=6&algorithm=SHA1&issuer=GuardPool

After parsing through the URI class:

  • scheme otpauth
  • host totp
  • path GuardPool:test
  • query secret=E55EYQJ5EUHX6ALB&period=30&digits=6&algorithm=SHA1&issuer=GuardPool

¶ Add dependency

Add sdk dependencies in dependencies in the project build.gradle file:

implementation 'cn.authing:otp:1.0.2'

¶ TOTPEntity class

TOTP account entity class, the parameters are as follows:

NameTypeDescription
pathStringPath, example:"GuardPool:test"
applicationStringName of organization or application, example:"GuardPool"
accountStringAccount name, example:"test"
secretStringSecret, example:"E55EYQJ5EUHX6ALB"
periodintCoken interval, In seconds, example:30s
digitsintSecret digit, example:6
algorithmStringalgorithm, example:"SHA1"、"SHA256"、"SHA512"
issuerStringissuer, example:"GuardPool"
totpCodeStringcode, example:"888888"

If the secret、period、digits、algorithm are set, TOTP code can be obtained directly through the getTotpCode() method.。

¶ TOTP class

TOTP Account data management class.

¶ Add data

Raw data binding can be passed directly through the bind() method

public static TOTPBindResult bind(Context context, String data) 

example:

String otpData = "otpauth://totp/GuardPool:test?secret=E55EYQJ5EUHX6ALB&period=30&digits=6&algorithm=SHA1&issuer=GuardPool";
TOTPBindResult bindResult = TOTP.bind(this, otpData);
if (bindResult.getCode() == TOTPBindResult.BIND_SUCCESS) {
    //Binding success
} else if (bindResult.getCode() == TOTPBindResult.UPDATED_ACCOUNT) {
    //Update account
} else if (bindResult.getCode() == TOTPBindResult.BIND_FAILURE) {
    //Binding failure
} 

It can also be added via the addTotp() method

example:

OTPEntity totp = new TOTPEntity();
totp.setPath("GuardPool:test");
totp.setApplication("GuardPool");
totp.setAccount("test");
totp.setSecret("E55EYQJ5EUHX6ALB");
totp.setAlgorithm("SHA1");
totp.setDigits(6);
totp.setPeriod(30);
totp.setIssuer("GuardPool");
TOTP.addTotp(this, totp);

¶ Update data

Update data

public static void updateTotp(Context context, TOTPEntity totp)

¶ Obtain data

Get all the data

public static List<TOTPEntity> getTotpList(Context context)

Get a single piece of data through path

public static TOTPEntity getTotp(Context context, String path)

¶ Delete data

Delete via entity class

public static void deleteTotp(Context context, TOTPEntity totp)

Delete by path

public static void deleteTotp(Context context, String path)

¶ TOTPGenerator class

TOTP verification code generation class, TOTP code can be generated by generateTOTP() method of the TOTPGenerator class itself

public static String generateTOTP(String secret, int period, int digits, String algorithm)

¶ Safety suggestion

For the sake of security, it is recommended to prohibit screenshots on the interface displaying code and add the following code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
Prev: Overseas Next: Device management
  • Data format
  • Add dependency
  • TOTPEntity class
  • TOTP class
  • TOTPGenerator class
  • Safety suggestion

User identity management

Integrated third-party login
Mobile phone number flash check (opens new window)
Universal login form component
Custom authentication process

Enterprise internal management

Single Sign On
Multi-factor Authentication
Authority Management

Developers

Development Document
Framework Integration
Blog (opens new window)
GitHub (opens new window)
Community User Center (opens new window)

Company

400 888 2106
sales@authing.cn
16 / F, Block B, NORTH STAR CENTURY CENTER, Beijing(Total)
room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)

Beijing ICP No.19051205-1

© Beijing Steamory Technology Co.