| Total Complexity | 4 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | trait QRCode |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Sending your secret key to Google API is a security issue. Developer must explicitly allow it. |
||
| 11 | */ |
||
| 12 | protected $allowInsecureCallToGoogleApis = false; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Creates a Google QR code url. |
||
| 16 | * |
||
| 17 | * @param string $company |
||
| 18 | * @param string $holder |
||
| 19 | * @param string $secret |
||
| 20 | * @param int $size |
||
| 21 | * |
||
| 22 | * @throws \PragmaRX\Google2FA\Exceptions\InsecureCallException |
||
| 23 | * |
||
| 24 | * @return string |
||
| 25 | */ |
||
| 26 | 2 | public function getQRCodeGoogleUrl($company, $holder, $secret, $size = 200) |
|
| 27 | { |
||
| 28 | 2 | if (!$this->allowInsecureCallToGoogleApis) { |
|
| 29 | 1 | throw new InsecureCallException("It's not secure to send secret keys to Google Apis, you have to explicitly allow it by calling \$google2fa->setAllowInsecureCallToGoogleApis(true)."); |
|
| 30 | } |
||
| 31 | |||
| 32 | 1 | return Url::generateGoogleQRCodeUrl( |
|
| 33 | 1 | 'https://chart.googleapis.com/', |
|
| 34 | 1 | 'chart', |
|
| 35 | 1 | 'chs='.$size.'x'.$size.'&chld=M|0&cht=qr&chl=', |
|
| 36 | 1 | $this->getQRCodeUrl($company, $holder, $secret) |
|
| 37 | ); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Creates a QR code url. |
||
| 42 | * |
||
| 43 | * @param $company |
||
| 44 | * @param $holder |
||
| 45 | * @param $secret |
||
| 46 | * |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | 1 | public function getQRCodeUrl($company, $holder, $secret) |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * AllowInsecureCallToGoogleApis setter. |
||
| 56 | * |
||
| 57 | * @param mixed $allowInsecureCallToGoogleApis |
||
| 58 | * |
||
| 59 | * @return QRCode |
||
| 60 | */ |
||
| 61 | 1 | public function setAllowInsecureCallToGoogleApis($allowInsecureCallToGoogleApis) |
|
| 66 | } |
||
| 67 | } |
||
| 68 |