Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
refactor: make email in qr-code information swappable (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur authored Jul 27, 2021
1 parent f768d9a commit 7620cac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private function registerDataBags(): void

### Two Factor Authentication

> Under the hood we use [**Pragmarx Google2fa-laravel**](https://github.com/antonioribeiro/google2fa-laravel#readme) package.
>
> For custom configuration like [generating QR-Code using SVG render](https://github.com/antonioribeiro/google2fa-laravel#qrcode-backend) instead of a default Imagemagick,
> you can [publish the default configuration](https://github.com/antonioribeiro/google2fa-laravel#publish-the-config-file) and adjust it as per your needs.
1. Add file download JS to Mix file

```js
Expand Down
2 changes: 1 addition & 1 deletion src/Components/TwoFactorAuthenticationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getTwoFactorQrCodeUrlProperty(): string
{
return app(TwoFactorAuthenticationProvider::class)->qrCodeUrl(
config('app.name'),
$this->user->email,
(string) data_get($this->user, config('fortify.username'), 'email'),
$this->state['two_factor_secret']
);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Components/TwoFactorAuthenticationFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use ARKEcosystem\Fortify\Components\TwoFactorAuthenticationForm;
use Illuminate\Support\Facades\Config;
use Livewire\Livewire;
use PragmaRX\Google2FALaravel\Google2FA;
use function Tests\createUserModel;
Expand Down Expand Up @@ -97,3 +98,25 @@
->call('disableTwoFactorAuthentication')
->assertDontSee('You have not enabled two factor authentication');
});

it('shows email after scanning qr-code on mobile device', function (): void {
$user = createUserModel();

$instance = Livewire::actingAs($user)
->test(TwoFactorAuthenticationForm::class)
->instance();

expect($instance->twoFactorQrCodeUrl)->toContain(urlencode($user->email));
});

it('shows username after scanning qr-code on mobile device', function (): void {
Config::set('fortify.username', 'username');

$user = createUserModel();

$instance = Livewire::actingAs($user)
->test(TwoFactorAuthenticationForm::class)
->instance();

expect($instance->twoFactorQrCodeUrl)->toContain(urlencode($user->username));
});

0 comments on commit 7620cac

Please sign in to comment.