You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make QR Code Provider a mandatory constructor argument
This change is discussed in #104
Currently, the library defaults to a QR Code Provider using an external
service, thus leaking secrets.
This change forces the definition of a QR Code Provider in the
constructor. It is a breaking change.
fixes#104
Copy file name to clipboardExpand all lines: docs/getting-started.md
+18-5
Original file line number
Diff line number
Diff line change
@@ -17,18 +17,31 @@ or if you have composer installed globally
17
17
composer require robthree/twofactorauth
18
18
```
19
19
20
+
**Note:** If you are not using a composer-aware framework, you should [include the composer loader yourself](https://getcomposer.org/doc/01-basic-usage.md#autoloading).
21
+
20
22
## 2. Create an instance
21
23
22
-
Now you can create an instance for use with your code
24
+
`TwoFactorAuth` constructor requires an object able to provide a QR Code image. It is the only mandatory argument. This lets you select your preferred QR Code generator/library.
25
+
26
+
See [QR code providers documentation](docs/qr-codes.md) for more information about the different possibilites.
27
+
28
+
Example code:
23
29
24
30
```php
25
31
use RobThree\Auth\TwoFactorAuth;
26
-
27
-
$tfa = new TwoFactorAuth();
32
+
use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; // if using Bacon
33
+
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider; // if using Endroid
34
+
35
+
// using Bacon
36
+
$tfa = new TwoFactorAuth(new BaconQrCodeProvider());
37
+
// using Endroid
38
+
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider());
39
+
// using a custom object
40
+
$tfa = new TwoFactorAuth(new MyQrCodeProvider());
41
+
// using named argument and a variable
42
+
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator);
28
43
```
29
44
30
-
**Note:** if you are not using a framework that uses composer, you should [include the composer loader yourself](https://getcomposer.org/doc/01-basic-usage.md#autoloading)
31
-
32
45
## 3. Shared secrets
33
46
34
47
When your user is setting up two-factor, or multi-factor, authentication in your project, you can create a secret from the instance.
Copy file name to clipboardExpand all lines: docs/qr-codes.md
+21-21
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,6 @@ You can also specify a size as a third argument which is 200 by default.
18
18
19
19
**Note:** by default, the QR code returned by the instance is generated from a third party across the internet. If the third party is encountering problems or is not available from where you have hosted your code, your user will likely experience a delay in seeing the QR code, if it even loads at all. This can be overcome with offline providers configured when you create the instance.
**Warning:** Whilst it is the default, this provider is not suggested for applications where absolute security is needed, because it uses an external service for the QR code generation. You can make use of the included offline providers listed below which generate locally.
[EndroidQrCodeProvider](qr-codes/endroid.md) and EndroidQrCodeWithLogoProvider
@@ -38,23 +28,33 @@ You can also specify a size as a third argument which is 200 by default.
38
28
39
29
## Custom Provider
40
30
41
-
If you wish to make your own QR Code provider to reference another service or library, it must implement the [IQRCodeProvider interface](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Qr/IQRCodeProvider.php).
31
+
If you wish to make your own QR Code provider to reference another service or library, it must implement the [IQRCodeProvider interface](../lib/Providers/Qr/IQRCodeProvider.php).
42
32
43
33
It is recommended to use similar constructor arguments as the included providers to avoid big shifts when trying different providers.
44
34
45
-
## Using a specific provider
46
-
47
-
If you do not want to use the default QR code provider, you can specify the one you want to use when you create your instance.
35
+
Example:
48
36
49
37
```php
50
38
use RobThree\Auth\TwoFactorAuth;
39
+
// using a custom object implementing IQRCodeProvider
40
+
$tfa = new TwoFactorAuth(new MyQrCodeProvider());
41
+
// using named argument and a variable
42
+
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator);
43
+
```
51
44
52
-
$qrCodeProvider = new YourChosenProvider();
45
+
## Online Providers
53
46
54
-
$tfa = new TwoFactorAuth(
55
-
issuer: "Your Company Or App Name",
56
-
qrcodeprovider: $qrCodeProvider
57
-
);
58
-
```
47
+
**Warning:** Using an external service for generating QR codes encoding authentication secrets is **not** recommended! You should instead make use of the included offline providers listed above.
0 commit comments