antonioribeiro / google2fa-qrcode

QRCode for Google2FA
MIT License
106 stars 25 forks source link

doesent show qrcode #10

Closed Link2Trials closed 3 years ago

Link2Trials commented 3 years ago

i tried everything but on php 7.3.5 and 7.4.9 it doesent show the qrcode with this

$inlineUrl = $google2fa->getQRCodeInline( $companyName, $companyEmail, $secretKey );

<img src="<?php echo $inlineUrl;?>">

antonioribeiro commented 3 years ago

Here's an running example you can use to start: https://phpsandbox.io/n/round-breeze-mzpk-pgrcn

ahmed-raza commented 1 year ago

Hi @antonioribeiro I am facing the exact same problem the qr image is not rendering at all. Can you please explain how to fix this?

Screenshot 2022-10-06 at 3 56 57 PM
Link2Trials commented 1 year ago

Hi @antonioribeiro I am facing the exact same problem the qr image is not rendering at all. Can you please explain how to fix this?

Screenshot 2022-10-06 at 3 56 57 PM

Hey the solution was in this post

https://stackoverflow.com/questions/36716797/imagemagick-non-conforming-drawing-primitive-definition-error-draw-c-drawi

It had to do wit the setLocale function from php

i removed the setlocale and it worked

ahmed-raza commented 1 year ago

Actually; $inlineUrl = $google2fa->getQRCodeInline( $companyName, $companyEmail, $secretKey );

Returns svg structure itself and not a url for <img src="{{ $inlineUrl }}" /> Which is causing the problem. Not sure how to fix this.

Link2Trials commented 1 year ago

Actually; $inlineUrl = $google2fa->getQRCodeInline( $companyName, $companyEmail, $secretKey );

Returns svg structure itself and not a url for <img src="{{ $inlineUrl }}" /> Which is causing the problem. Not sure how to fix this.

$inlineUrl = $google2fa->getQRCodeInline( 'Name', $email, $secret );

this works when i remove the setLocale

ahmed-raza commented 1 year ago

Nevermind, I ended up rendering the svg structure as is.

w5m commented 1 year ago

Actually; $inlineUrl = $google2fa->getQRCodeInline( $companyName, $companyEmail, $secretKey );

Returns svg structure itself and not a url for <img src="{{ $inlineUrl }}" /> Which is causing the problem. Not sure how to fix this.

I encountered exactly the same issue @ahmed-raza (and can no longer view the example @antonioribeiro posted).

The fix was two-fold...

  1. Utilise a Data URL by prefixing the data (in this case, the generated SVG structure) with a MIME type to indicate what type of data will follow (i.e. data:image/svg+xml;charset=utf-8,).
  2. Percent-encode (URL-encode) the data using the PHP rawurlencode function.

My final code looked like this and successfully rendered a QR Code in Chrome, Firefox and Edge... <img src="data:image/svg+xml;charset=utf-8,{{ rawurlencode($inlineUrl) }}" alt="QR Code for Two-Factor Authentication" />

peroln commented 3 months ago

Actually; $inlineUrl = $google2fa->getQRCodeInline( $companyName, $companyEmail, $secretKey ); Returns svg structure itself and not a url for <img src="{{ $inlineUrl }}" /> Which is causing the problem. Not sure how to fix this.

I encountered exactly the same issue @ahmed-raza (and can no longer view the example @antonioribeiro posted).

The fix was two-fold...

  1. Utilise a Data URL by prefixing the data (in this case, the generated SVG structure) with a MIME type to indicate what type of data will follow (i.e. data:image/svg+xml;charset=utf-8,).
  2. Percent-encode (URL-encode) the data using the PHP rawurlencode function.

My final code looked like this and successfully rendered a QR Code in Chrome, Firefox and Edge... <img src="data:image/svg+xml;charset=utf-8,{{ rawurlencode($inlineUrl) }}" alt="QR Code for Two-Factor Authentication" />

The problem was similar. Fixed it on your advice. Thanks