-
Notifications
You must be signed in to change notification settings - Fork 209
Add Two Factor Authentication for Vue Starter Kit #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pushpak1300
wants to merge
68
commits into
main
Choose a base branch
from
feat/two-factor-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 32 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
7ef8d7e
feat: implement two-factor authentication functionality and UI enhanc…
pushpak1300 263cdef
refactor: extract two-factor authentication logic to composable for b…
pushpak1300 94b4248
refactor: move two-factor authentication logic from composable to pag…
pushpak1300 c284c85
refactor: simplify two-factor authentication logic with form componen…
pushpak1300 62c4b52
feat: add PinInput component and update TwoFactor UI with reka-ui 2.4…
pushpak1300 0fb05f8
refactor: replace reka-ui PinInput with custom implementation and opt…
pushpak1300 ae01a15
refactor: revert unneeded changes
pushpak1300 ee18d0f
Merge branch 'main' into feat/two-factor-auth
pushpak1300 ea4d231
refactor: simplify two-factor authentication
pushpak1300 b1b183d
feat: update two-factor authentication to delay login until confirmation
pushpak1300 7f78d7e
wip
pushpak1300 ebda2c6
wip
pushpak1300 cae3c55
refactor: centralize two-factor authentication logic, improve UI stat…
pushpak1300 14f1165
refactor: streamline TwoFactor components, simplify form handling, an…
pushpak1300 1a24366
refactor: centralize clipboard and two-factor authentication logic, e…
pushpak1300 8bc54c9
refactor: enhance TwoFactor UI components with reusable Card layout, …
pushpak1300 da99c25
fix: use `hasEnabledTwoFactorAuthentication` for improved logic clari…
pushpak1300 f93dc53
refactor: streamline TwoFactor UI logic, improve recovery mode toggle…
pushpak1300 f608bc4
refactor: simplify TwoFactor test structure, replace manual assertion…
pushpak1300 b6610fc
chore: add newline to end of TwoFactorAuthenticationTest file
pushpak1300 8ba762c
refactor: enhance TwoFactor UI with conditional enable button logic, …
pushpak1300 c4d5d06
refactor: enhance TwoFactor UI with conditional enable button logic, …
pushpak1300 bd1d90c
refactor: inline two-factor authentication composable logic into TwoF…
pushpak1300 0fe2452
refactor: remove unused `ref` and `focus` logic from Input component …
pushpak1300 a6d28f4
refactor: enhance two-factor authentication flow with middleware chec…
pushpak1300 fecc5d4
refactor: simplify TwoFactor component with async/await, refine recov…
pushpak1300 ef2931c
refactor: reset setup data on modal close, improve form handling, and…
pushpak1300 a162314
refactor: add reusable reset methods for reactive states, simplify Tw…
pushpak1300 bc8440a
fix: formatting issue
pushpak1300 d0a80eb
fix: conditionally apply password confirmation middleware
pushpak1300 e4b915f
chore: update lock file
pushpak1300 2e55156
fix: make component reactive
pushpak1300 9b81898
wip
pushpak1300 08b9471
refactor: split the component
pushpak1300 021db0d
refactor: use composable
pushpak1300 9317296
refactor: remove redundant type definition
pushpak1300 9782812
refactor: remove custom useClipboard composable
pushpak1300 c0ae075
refactor: simplify recovery codes visibility logic
pushpak1300 b1ddcb5
Merge branch 'main' into feat/two-factor-auth
pushpak1300 6ff5d5d
fix: merge issues
pushpak1300 b083e76
refactor: update two-factor authentication forms to use route helpers
pushpak1300 b2ef754
refactor: test
pushpak1300 31e6061
refactor: improve two-factor authentication tests and enhance readabi…
pushpak1300 cc8f893
refactor: update two-factor authentication tests for consistency and …
pushpak1300 7b4e4e4
wip
pushpak1300 e2e382d
Move conditional middleware from route to controller
pushpak1300 f2888c1
Fix tests to be consistent based on config
pushpak1300 f8ca148
Remove comments
pushpak1300 b85a0d7
refactor: simplify toggleRecoveryCodesVisibility function signature
pushpak1300 7309dde
remove duplicate type defination
pushpak1300 52b681e
fix type definition
pushpak1300 b314f93
More Fixes
pushpak1300 bfcb743
fix types
pushpak1300 afa80b5
fix wayfinder routes
pushpak1300 e4bff4d
refactor ui to use defineModal and remove unnecessary things
pushpak1300 c849ded
remove unneeded async attribute
pushpak1300 d073337
remove redundant attribute action
pushpak1300 00db807
fix: finish state
pushpak1300 f991021
Merge branch 'main' into feat/two-factor-auth
pushpak1300 5fdfd1d
fix: merge conflicts
pushpak1300 3f3d9c7
state cleanup
pushpak1300 ae76fd8
Merge branch 'main' into feat/two-factor-auth
pushpak1300 27da01f
fix typo
pushpak1300 0b3afa0
use arrow functions
pushpak1300 aeffd88
Move trait to form-request
pushpak1300 2b20426
Formatting
pushpak1300 17f4ec7
various formatting tweaks
taylorotwell 7c3811c
Update TwoFactorSetupModal.vue
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
/storage/*.key | ||
/storage/pail | ||
/vendor | ||
.DS_Store | ||
.env | ||
.env.backup | ||
.env.production | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
app/Http/Controllers/Auth/ConfirmablePasswordController.php
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
app/Http/Controllers/Concerns/ConfirmsTwoFactorAuthentication.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Concerns; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; | ||
use Laravel\Fortify\Features; | ||
|
||
trait ConfirmsTwoFactorAuthentication | ||
{ | ||
/** | ||
* Validate the two-factor authentication state for the request. | ||
*/ | ||
protected function validateTwoFactorAuthenticationState(Request $request): void | ||
{ | ||
if (! Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm')) { | ||
return; | ||
} | ||
|
||
$currentTime = time(); | ||
|
||
// Notate totally disabled state in session... | ||
if ($this->twoFactorAuthenticationDisabled($request)) { | ||
$request->session()->put('two_factor_empty_at', $currentTime); | ||
} | ||
|
||
// If was previously totally disabled this session but is now confirming, notate time... | ||
if ($this->hasJustBegunConfirmingTwoFactorAuthentication($request)) { | ||
$request->session()->put('two_factor_confirming_at', $currentTime); | ||
} | ||
|
||
// If the profile is reloaded and is not confirmed but was previously in confirming state, disable... | ||
if ($this->neverFinishedConfirmingTwoFactorAuthentication($request, $currentTime)) { | ||
app(DisableTwoFactorAuthentication::class)(Auth::user()); | ||
|
||
$request->session()->put('two_factor_empty_at', $currentTime); | ||
$request->session()->remove('two_factor_confirming_at'); | ||
} | ||
} | ||
|
||
/** | ||
* Determine if two-factor authentication is totally disabled. | ||
*/ | ||
protected function twoFactorAuthenticationDisabled(Request $request): bool | ||
{ | ||
return is_null($request->user()->two_factor_secret) && | ||
is_null($request->user()->two_factor_confirmed_at); | ||
} | ||
|
||
/** | ||
* Determine if two-factor authentication is just now being confirmed within the last request cycle. | ||
*/ | ||
protected function hasJustBegunConfirmingTwoFactorAuthentication(Request $request): bool | ||
{ | ||
return ! is_null($request->user()->two_factor_secret) && | ||
is_null($request->user()->two_factor_confirmed_at) && | ||
$request->session()->has('two_factor_empty_at') && | ||
is_null($request->session()->get('two_factor_confirming_at')); | ||
} | ||
|
||
/** | ||
* Determine if two-factor authentication was never totally confirmed once confirmation started. | ||
*/ | ||
protected function neverFinishedConfirmingTwoFactorAuthentication(Request $request, int $currentTime): bool | ||
{ | ||
return ! array_key_exists('code', $request->session()->getOldInput()) && | ||
is_null($request->user()->two_factor_confirmed_at) && | ||
$request->session()->get('two_factor_confirming_at', 0) != $currentTime; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/Http/Controllers/Settings/TwoFactorAuthenticationController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings; | ||
|
||
use App\Http\Controllers\Concerns\ConfirmsTwoFactorAuthentication; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response as HttpResponse; | ||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
use Laravel\Fortify\Features; | ||
|
||
class TwoFactorAuthenticationController extends Controller | ||
{ | ||
use ConfirmsTwoFactorAuthentication; | ||
|
||
/** | ||
* Show the user's two-factor authentication settings page. | ||
*/ | ||
public function show(Request $request): Response | ||
{ | ||
if (! Features::enabled(Features::twoFactorAuthentication())) { | ||
abort(HttpResponse::HTTP_FORBIDDEN, 'Two factor authentication is disabled.'); | ||
} | ||
|
||
$this->validateTwoFactorAuthenticationState($request); | ||
|
||
return Inertia::render('settings/TwoFactor', [ | ||
'requiresConfirmation' => Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm'), | ||
'twoFactorEnabled' => $request->user()->hasEnabledTwoFactorAuthentication(), | ||
]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Cache\RateLimiting\Limit; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\RateLimiter; | ||
use Illuminate\Support\ServiceProvider; | ||
use Inertia\Inertia; | ||
use Laravel\Fortify\Fortify; | ||
|
||
class FortifyServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register any application services. | ||
*/ | ||
public function register(): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Bootstrap any application services. | ||
*/ | ||
public function boot(): void | ||
{ | ||
Fortify::twoFactorChallengeView(function () { | ||
return Inertia::render('auth/TwoFactorChallenge'); | ||
}); | ||
|
||
Fortify::confirmPasswordView(function () { | ||
return Inertia::render('auth/ConfirmPassword'); | ||
}); | ||
|
||
RateLimiter::for('two-factor', function (Request $request) { | ||
return Limit::perMinute(5)->by($request->session()->get('login.id')); | ||
}); | ||
pushpak1300 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
return [ | ||
App\Providers\AppServiceProvider::class, | ||
App\Providers\FortifyServiceProvider::class, | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.