DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on

Key not recognized in rotp rails gem when scanning with Google Authenticator

Yesterday I was updating my rails project with "bundle update" and rotp gem goes haywired. The previous otp_secret of User(Devise Model) is something like this


and after updating to rotp 6.3.0, the Google Authenticator didn't recognized the generated QR code anymore.

It is because in the newer version the otp_secret must only be the string, no json or whatsoever. Something like this


The above string can be generated using class method called

Enter fullscreen mode Exit fullscreen mode

Following is the way to return svg to show in the view

    def qrcode
        issuer = "My Application Name"

        # Generate a TOTP provisioning URI with the issuer
        totp =, issuer: issuer)
        provisioning_uri = totp.provisioning_uri(
        qrcode =

        @svg = qrcode.as_svg(
          offset: 0,
          color: '000',
          shape_rendering: 'crispEdges',
          module_size: 3,
          use_path: true,
          file: nil


Enter fullscreen mode Exit fullscreen mode

Then you can show the svg in the view easily

    <div class="text-center">
      <p>Scan the Below QR Code with Google Authenticator or Microsoft Authenticator.</p></br>
      <%= raw @svg %>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)