Skip to content

Commit 7277b64

Browse files
saibotkDaneEveritt
authored andcommitted
Replace 2FA QR Code generation (pterodactyl#1548)
Due to the Google API for generating the 2FA QR code will be shut down on 14.04.2019, this adds the package "pragmarx/google2fa-qrcode" and updates "pragmarx/google2fa" to version 5.x. Due to now using BaconQR, Pterodactyl now needs the php-imagick extension to render the images.
1 parent 4460b68 commit 7277b64

File tree

4 files changed

+166
-21
lines changed

4 files changed

+166
-21
lines changed

app/Services/Users/TwoFactorSetupService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Pterodactyl\Services\Users;
1111

1212
use Pterodactyl\Models\User;
13-
use PragmaRX\Google2FA\Google2FA;
13+
use PragmaRX\Google2FAQRCode\Google2FA;
1414
use Illuminate\Contracts\Encryption\Encrypter;
1515
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1616
use Illuminate\Contracts\Config\Repository as ConfigRepository;
@@ -28,7 +28,7 @@ class TwoFactorSetupService
2828
private $encrypter;
2929

3030
/**
31-
* @var \PragmaRX\Google2FA\Google2FA
31+
* @var PragmaRX\Google2FAQRCode\Google2FA
3232
*/
3333
private $google2FA;
3434

@@ -42,7 +42,7 @@ class TwoFactorSetupService
4242
*
4343
* @param \Illuminate\Contracts\Config\Repository $config
4444
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
45-
* @param \PragmaRX\Google2FA\Google2FA $google2FA
45+
* @param PragmaRX\Google2FAQRCode\Google2FA $google2FA
4646
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
4747
*/
4848
public function __construct(
@@ -70,7 +70,7 @@ public function __construct(
7070
public function handle(User $user): string
7171
{
7272
$secret = $this->google2FA->generateSecretKey($this->config->get('pterodactyl.auth.2fa.bytes'));
73-
$image = $this->google2FA->getQRCodeGoogleUrl($this->config->get('app.name'), $user->email, $secret);
73+
$image = $this->google2FA->getQRCodeInline($this->config->get('app.name'), $user->email, $secret);
7474

7575
$this->repository->withoutFreshModel()->update($user->id, [
7676
'totp_secret' => $this->encrypter->encrypt($secret),

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"lord/laroute": "^2.4",
3030
"matriphe/iso-639": "^1.2",
3131
"nesbot/carbon": "^1.22",
32-
"pragmarx/google2fa": "^2.0",
32+
"pragmarx/google2fa": "^5.0",
33+
"pragmarx/google2fa-qrcode": "^1.0.3",
3334
"predis/predis": "^1.1",
3435
"prologue/alerts": "^0.4",
3536
"ramsey/uuid": "^3.7",

composer.lock

Lines changed: 157 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Unit/Services/Users/TwoFactorSetupServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Mockery as m;
66
use Tests\TestCase;
77
use Pterodactyl\Models\User;
8-
use PragmaRX\Google2FA\Google2FA;
8+
use PragmaRX\Google2FAQRCode\Google2FA;
99
use Illuminate\Contracts\Config\Repository;
1010
use Illuminate\Contracts\Encryption\Encrypter;
1111
use Pterodactyl\Services\Users\TwoFactorSetupService;
@@ -24,7 +24,7 @@ class TwoFactorSetupServiceTest extends TestCase
2424
private $encrypter;
2525

2626
/**
27-
* @var \PragmaRX\Google2FA\Google2FA|\Mockery\Mock
27+
* @var PragmaRX\Google2FAQRCode\Google2FA|\Mockery\Mock
2828
*/
2929
private $google2FA;
3030

@@ -56,7 +56,7 @@ public function testSecretAndImageAreReturned()
5656
$this->config->shouldReceive('get')->with('pterodactyl.auth.2fa.bytes')->once()->andReturn(32);
5757
$this->google2FA->shouldReceive('generateSecretKey')->with(32)->once()->andReturn('secretKey');
5858
$this->config->shouldReceive('get')->with('app.name')->once()->andReturn('CompanyName');
59-
$this->google2FA->shouldReceive('getQRCodeGoogleUrl')->with('CompanyName', $model->email, 'secretKey')->once()->andReturn('http://url.com');
59+
$this->google2FA->shouldReceive('getQRCodeInline')->with('CompanyName', $model->email, 'secretKey')->once()->andReturn('http://url.com');
6060
$this->encrypter->shouldReceive('encrypt')->with('secretKey')->once()->andReturn('encryptedSecret');
6161
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, ['totp_secret' => 'encryptedSecret'])->once()->andReturnNull();
6262

0 commit comments

Comments
 (0)