scheb / 2fa

Two-factor authentication for Symfony applications 🔐
MIT License
495 stars 72 forks source link

Unable to decode the secret. Is it correctly base32 encoded? #218

Closed FVSoftwareDeveloper closed 7 months ago

FVSoftwareDeveloper commented 7 months ago

Bundle version: ^5.13 Symfony version: ^5.4 PHP version: 7.4.6

Description

Any code that I send to the checkcode function returns the message shown below:

Unable to decode the secret. Is it correctly base32 encoded?

I'm attempting to validate code, sending it a wring code to receive invalid code, and handling the exception on my end.

Additional Context

See the configuration reference at https://symfony.com/bundles/SchebTwoFactorBundle/5.x/configuration.html

configurantion file scheb_2fa.yaml

scheb_two_factor: security_tokens:

Stack trace

RuntimeException: Unable to decode the secret. Is it correctly base32 encoded? in /var/www/html/vendor/spomky-labs/otphp/src/OTP.php:95\nStack trace:\n#0 /var/www/html/vendor/spomky-labs/otphp/src/OTP.php(45): OTPHP\OTP->getDecodedSecret()\n#1 /var/www/html/vendor/spomky-labs/otphp/src/TOTP.php(55): OTPHP\OTP->generateOTP(56865226)\n#2 /var/www/html/vendor/spomky-labs/otphp/src/TOTP.php(84): OTPHP\TOTP->at(1705956780)\n#3 /var/www/html/vendor/spomky-labs/otphp/src/TOTP.php(74): OTPHP\TOTP->verifyOtpWithWindow('461456', 1705956780, 30)\n#4 /var/www/html/vendor/scheb/2fa-google-authenticator/Security/TwoFactor/Provider/Google/GoogleAuthenticator.php(36): OTPHP\TOTP->verify('461456', 1705956780, 30)\n#5 /var/www/html/src/v2/Service/MFA/MFAAuthCodesService.php(153): Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator->checkCode(Object(App\Entity\User\User), '461456')\n#6 /var/www/html/src/v2/Controller/MFA/MFAAuthCodesController.php(135): App\v2\Service\MFA\MFAAuthCodesService->getValidateCode('461456')\n#7 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(163): App\v2\Controller\MFA\MFAAuthCodesController->getCheckCode(Object(Symfony\Component\HttpFoundation\Request))\n#8 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(75): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)\n#9 /var/www/html/vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#10 /var/www/html/public/index.php(25): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))\n#11 {main}"

scheb commented 7 months ago

The secret value that you provide through getGoogleAuthenticatorSecret has to be encoded base32.

The bundle comes with a helper method to create valid secret values: getGoogleAuthenticatorSecret