Back

Invalid Token verifying TOTP MFA

  • 0
  • Cloud
Yestix
4 Feb, 2025, 19:55

Hi, I always get the error messages that the token I pass is invalid although it is the one from the Authenticator App which has been added by scanning the QR code.

This is my code: async createMFA() { try { account.updateMFA(true);

TypeScript
        const { secret, uri } = await account.createMfaAuthenticator(
            AuthenticatorType.Totp // type
        );
        
        console.log("Authenticator URI:", uri, "Secret:", secret);
        const result = await avatars.getQR(
            uri,  // text
            800,  // size (optional)
            0,  // margin (optional)
            false // download (optional)
        );

        const qrString = result.toString();
        console.log("QR Code String:", qrString);
        
        return qrString

        
    } catch (error) {
       throw(error)
    }
}

async activateMFA(OTP: string) {
    try {                      
        const result = await account.updateMfaAuthenticator(
            AuthenticatorType.Totp, // type
            OTP // otp
        );
        console.log(result);
        if (result) {
            const response = await account.updateMFA(true);         
        }
    } catch (error) {
       console.log('Error' + error)
    }
}

Can someone help me please?

TL;DR
Error: Invalid Token when verifying TOTP MFA. Developers are encountering issues with verifying TOTP MFA tokens, even though they are using the correct token from the Authenticator App. The provided code snippets show functions for creating and activating MFA. Solution: - Double-check that the TOTP OTP (One-Time Password) being passed in the activateMFA function is correct. - Ensure that the implementation of the createMFA and activateMFA functions is correct and matches the server-side MFA validation process. - Troubleshoot any discrepancies between the creation of the QR code and the scanning process to ensure accurate encoding of the secret
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more