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 PR #125
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 The public function getQRCodeProvider() has been removed. It is provided by the user in the constructor, so it doesn't make a lot of sense to keep a getter around if we're not using it internally.
Copy file name to clipboardExpand all lines: docs/getting-started.md
+16-11Lines changed: 16 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,28 +7,33 @@ title: Getting Started
7
7
8
8
The best way of making use of this project is by installing it with [composer](https://getcomposer.org/doc/01-basic-usage.md).
9
9
10
-
```
11
-
php composer.phar require robthree/twofactorauth
12
-
```
13
-
14
-
or if you have composer installed globally
15
-
16
10
```
17
11
composer require robthree/twofactorauth
18
12
```
19
13
20
14
## 2. Create an instance
21
15
22
-
Now you can create an instance for use with your code
16
+
`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.
17
+
18
+
See [QR code providers documentation](qr-codes.md) for more information about the different possibilites.
19
+
20
+
Example code:
23
21
24
22
```php
25
23
use RobThree\Auth\TwoFactorAuth;
26
-
27
-
$tfa = new TwoFactorAuth();
24
+
use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; // if using Bacon
25
+
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider; // if using Endroid
26
+
27
+
// using Bacon
28
+
$tfa = new TwoFactorAuth(new BaconQrCodeProvider());
29
+
// using Endroid
30
+
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider());
31
+
// using a custom object implementing IQRCodeProvider interface
32
+
$tfa = new TwoFactorAuth(new MyQrCodeProvider());
33
+
// using named argument and a variable
34
+
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator);
28
35
```
29
36
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
37
## 3. Shared secrets
33
38
34
39
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
+22-24Lines changed: 22 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: QR Codes
5
5
6
6
An alternative way of communicating the secret to the user is through the use of [QR Codes](http://en.wikipedia.org/wiki/QR_code) which most if not all authenticator mobile apps can scan.
7
7
8
-
This can avoid accidental typing errors and also pre-set some text values within the users app.
8
+
This can avoid accidental typing errors and also pre-set some text values within the two factor authentication mobile application.
9
9
10
10
You can display the QR Code as a base64 encoded image using the instance as follows, supplying the users name or other public identifier as the first argument
11
11
@@ -16,18 +16,6 @@ You can display the QR Code as a base64 encoded image using the instance as foll
16
16
17
17
You can also specify a size as a third argument which is 200 by default.
18
18
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 +26,33 @@ You can also specify a size as a third argument which is 200 by default.
38
26
39
27
## Custom Provider
40
28
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).
29
+
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
30
43
31
It is recommended to use similar constructor arguments as the included providers to avoid big shifts when trying different providers.
44
32
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.
33
+
Example:
48
34
49
35
```php
50
36
use RobThree\Auth\TwoFactorAuth;
37
+
// using a custom object implementing IQRCodeProvider
38
+
$tfa = new TwoFactorAuth(new MyQrCodeProvider());
39
+
// using named argument and a variable
40
+
$tfa = new TwoFactorAuth(qrcodeprovider: $qrGenerator);
41
+
```
42
+
43
+
## Online Providers
51
44
52
-
$qrCodeProvider = new YourChosenProvider();
45
+
**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