fix: correctly generates otp code from token with extra padding

This commit is contained in:
Nelson Isioma 2025-02-23 13:47:41 +01:00
parent ddaa090bc7
commit c1904ca20a
2 changed files with 39 additions and 0 deletions

View file

@ -33,6 +33,9 @@ func GenerateOTPCode(token string, when time.Time) (string, error) {
// It should be uppercase always
token = strings.ToUpper(token)
// Remove all the extra "=" padding at the end
token = strings.TrimRight(token, "=")
secretBytes, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(token)
if err != nil {
return "", fmt.Errorf("Decoding token string: %w", err)