TOTP in Offline Mode

šŸ““ Offline Considerations for TOTP – REL-ID SDK

🧭 What "Offline" Means

In REL-ID SDK, offline mode refers to scenarios where:

  • Server communication is not possible or deliberately restricted
  • Device must perform local authentication and OTP generation
  • Common in secure environments, travel, rural use cases, etc.

šŸ” Offline TOTP Support

REL-ID SDK can generate TOTP without a server connection if the following conditions are met:

āœ… Prerequisites

RequirementDescription
āœ… Pre-authenticated sessionUser must have previously authenticated online
āœ… Provisioned TOTP secretServer must have issued TOTP seed/token during setup
āœ… LDA configured (Fingerprint, Pattern)Used for local identity verification before TOTP generation

šŸ” Offline Behavior of onTOTPGenerated


ConditionWill onTOTPGenerated be triggered?
Device has LDA or cached password authāœ… Yes
TOTP secret/token was provisioned earlierāœ… Yes
SDK policy allows offline OTP generationāœ… Yes
Device lacks LDA + password not cachedāŒ No – SDK cannot generate OTP
Device TOTP setup was never completed onlineāŒ No – missing cryptographic seed

šŸ“‹ TOTP Flow in Offline Mode

flowchart TD
    A[🌐 App Detects Offline Environment] --> A1[App calls fetchRegisteredTOTPUsers]
    A1 -->|User registered for TOTP| A2[App shows Generate TOTP option]
    A2 --> B[šŸ§‘ User Selects 'Generate TOTP']
    B --> C[šŸ” SDK Checks for LDA or Cached Credentials]
    
    C -->|āœ… LDA Available| D1[šŸ”“ Perform Local Biometric/Pattern Auth]
    C -->|āŒ LDA Not Available| D2[šŸ”‘ Fallback to Password Validation SDK triggers getTOTPPassword]
    D2 --> D3[App calls setTOTPPassword]
    D3 --> E[🧮 SDK Generate TOTP via Local Algorithm]
    D1 --> E
    E --> F[SDK emits onTOTPGenerated]
    F --> G[šŸ“² App Displays TOTP and Expiry Timer]

    %% Success Callback Styling
    style C fill:#d4fdd4,stroke:#228b22,stroke-width:2px
    style F fill:#d4fdd4,stroke:#228b22,stroke-width:2px
    style onIDVAdditionalDocumentScan fill:#d4fdd4,stroke:#228b22,stroke-width:2px

    %% App-Initiated Call Styling
    style A1 fill:#ffe4b3,stroke:#ff8c00,stroke-width:2px
    style D3 fill:#ffe4b3,stroke:#ff8c00,stroke-width:2px

🟩 Green - Callbacks issued by REL-ID SDK
🟧 Orange - APIs invoked by the Client App


šŸ”„ Comparison: Online vs Offline TOTP

FeatureOnline TOTPOffline TOTP
Server Requiredāœ… YesāŒ No
LDA RequiredOptional (based on policy)āœ… Yes (mandatory for local challenge)
Password PromptMay be requiredOnly if LDA unavailable
Secret ProvisioningLive via serverCached from earlier session
Verification MethodServer-side OTP matchConsuming app/server must validate

🧠 Developer Best Practices

  • āœ… Prompt user to enable LDA during initial login.
  • āœ… Use fetchRegisteredTOTPUsers() to check eligibility in advance.
  • āœ… Cache fallback flags or TOTP readiness when connected.
  • āŒ Do not attempt generateTOTP() offline unless prerequisites are met.
  • āœ… Always show retry/fallback options when offline auth fails.

šŸ” Notes for Developers

  • This flow is entirely local and does not require network connectivity.
  • Ensure biometric/pattern authentication is properly configured during activation.
  • Fallback to cached password depends on prior successful login and policy settings.
  • TOTP is time-based and will auto-expire as per the configured validity duration.