File tree 2 files changed +17
-0
lines changed 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Vectorface \OtpAuth ;
4
4
5
+ use Endroid \QrCode \Builder \Builder ;
6
+ use Endroid \QrCode \Writer \PngWriter ;
5
7
use Vectorface \OtpAuth \Paramters \Algorithm ;
6
8
use Vectorface \OtpAuth \Paramters \Type ;
7
9
@@ -136,4 +138,15 @@ public function __toString(): string
136
138
{
137
139
return $ this ->getUri ();
138
140
}
141
+
142
+ public function getQRCodeDataUri (): string
143
+ {
144
+ return Builder::create ()
145
+ ->data ($ this ->getUri ())
146
+ ->writer (new PngWriter )
147
+ ->size (260 )
148
+ ->margin (10 )
149
+ ->build ()
150
+ ->getDataUri ();
151
+ }
139
152
}
Original file line number Diff line number Diff line change @@ -19,8 +19,12 @@ public function synopsis()
19
19
->account ("MyAcct " )
20
20
->secret ("FOO " );
21
21
22
+ /* The builder can generate otpauth URLs */
22
23
$ this ->assertEquals ("otpauth://totp/MyAcct?secret=FOO " , "$ uriBuilder " );
23
24
25
+ /* ... or QR codes as data URIs */
26
+ $ this ->assertStringStartsWith ("data:image/png;base64, " , $ uriBuilder ->getQRCodeDataUri ());
27
+
24
28
/* It is also possible to construct complex OTP URIs, including HOTP */
25
29
$ uriBuilder = (new UriBuilder ())
26
30
->type (Type::HOTP )
You can’t perform that action at this time.
0 commit comments