Allow for arguments when calling rodauth.otp_qr_code or set viewbox: true

20 views
Skip to first unread message

Mathias Gruschwitz

unread,
Nov 2, 2021, 10:35:10 AM11/2/21
to Rodauth
Hello Jeremy,

I am using Janko's great rails gem. The OTP setup view contains the call rodauth.otp_qr_code.html_safe.

The rendered SVG contains the attributes height and width making it somewhat rigid to style (it has the subtle size of 456px by 456px).
rqrcode allows to pass in some arguments to control the output.
Do you think it might be a good addition to rodauth to allow the options to be passed to the method otp_qr_code?

Alternatively, the option :viewbox=>true would be a great default.

Let me know what your thoughts are.

Best,
Mathias

Jeremy Evans

unread,
Nov 2, 2021, 10:49:03 AM11/2/21
to rod...@googlegroups.com
I think you can already get what you want by using the following in your Rodauth configuration:

    otp_qr_code do
      RQRCode::QRCode.new(otp_provisioning_uri).as_svg(:module_size=>8, :viewbox=>true)
    end

Will that work for you currently?

In terms of possible improvements, I could make the options passed to as_svg configurable, so you could do the following and be able to override less:

    otp_qr_code_svg_opts do
      {:module_size=>8, :viewbox=>true}
    end

I can also look at making :viewbox=>true the default.  If there are any backwards compatibility issues, it might have to wait until the next major version though.

Thanks,
Jeremy

Jeremy Evans

unread,
Nov 2, 2021, 11:16:41 AM11/2/21
to rod...@googlegroups.com
On Tue, Nov 2, 2021 at 7:48 AM Jeremy Evans <jeremy...@gmail.com> wrote:
I can also look at making :viewbox=>true the default.  If there are any backwards compatibility issues, it might have to wait until the next major version though.

Looks like there are no problems with making :viewbox=>true the default, so I made that change: https://github.com/jeremyevans/rodauth/commit/33e7dbd4aa08e9b3cd36550af49a1a96ff4b3cc1

Thanks,
Jeremy

Mathias Gruschwitz

unread,
Nov 2, 2021, 4:58:08 PM11/2/21
to Rodauth
True,  overriding the method in the config makes totally sense. Thanks for the nudge ;)

Thank you for your prompt response!

Reply all
Reply to author
Forward
0 new messages