From 392d14e0e1cac19a3726296fc8660b1ae567a966 Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Sun, 27 Jul 2025 23:15:54 -0400 Subject: [PATCH] WIP --- app/Http/Controllers/OIDCController.php | 14 +++++++-- app/Livewire/AppInfoModal.php | 5 --- app/Livewire/Forms/UserProfile.php | 28 ++++++++++------- ...dd_extra_info_to_authentication_tokens.php | 31 +++++++++++++++++++ package-lock.json | 2 +- resources/views/dashboard.blade.php | 6 ++-- .../livewire/forms/user-profile.blade.php | 4 +++ resources/views/logged-out.blade.php | 8 +++++ routes/web.php | 1 + 9 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 database/migrations/2025_07_28_030305_add_extra_info_to_authentication_tokens.php create mode 100644 resources/views/logged-out.blade.php diff --git a/app/Http/Controllers/OIDCController.php b/app/Http/Controllers/OIDCController.php index 8c35a36..7aa270f 100644 --- a/app/Http/Controllers/OIDCController.php +++ b/app/Http/Controllers/OIDCController.php @@ -134,8 +134,13 @@ class OIDCController extends Controller $accessToken = Str::random(64); - $user->tokens()->updateOrCreate(['application_id' => $client->id], [ - 'token' => $accessToken + $user->tokens()->create([ + 'application_id' => $client->id, + 'token' => $accessToken, + 'issued_at' => now()->toDateTimeString(), + 'expires_at' => now()->addMonth()->toDateTimeString(), + 'ip' => $request->ip(), + 'user_agent' => $request->userAgent(), ]); return response()->json([ @@ -217,4 +222,9 @@ class OIDCController extends Controller ] ]); } + + public function logout(Request $request) + { + return view('logged-out'); + } } diff --git a/app/Livewire/AppInfoModal.php b/app/Livewire/AppInfoModal.php index c36795e..58f211d 100644 --- a/app/Livewire/AppInfoModal.php +++ b/app/Livewire/AppInfoModal.php @@ -15,11 +15,6 @@ class AppInfoModal extends Component public string $query = ''; public ?string $icon = null; - public function mount() - { - $this->loadApp(4); - } - public function updated($prop) { if ($prop == "query") { diff --git a/app/Livewire/Forms/UserProfile.php b/app/Livewire/Forms/UserProfile.php index 26bd403..1c1b9f6 100644 --- a/app/Livewire/Forms/UserProfile.php +++ b/app/Livewire/Forms/UserProfile.php @@ -18,7 +18,7 @@ class UserProfile extends Component public string $name = ''; public string $email = ''; public ?string $preferred_username = null; - public string $avatar = ''; + public ?string $avatar = null; #[Validate('image|max:10000')] public $avatarUpload; // Password @@ -68,22 +68,26 @@ class UserProfile extends Component $this->dispatch('profile-updated', name: $user->name); } - /** - * Send an email verification notification to the current user. - */ - public function resendVerificationNotification(): void + public function updatePassword(): void { - $user = Auth::user(); + try { + $validated = $this->validate([ + 'current_password' => ['required', 'string', 'current_password'], + 'password' => ['required', 'string', PasswordRule::defaults(), 'confirmed'], + ]); + } catch (ValidationException $e) { + $this->reset('current_password', 'password', 'password_confirmation'); - if ($user->hasVerifiedEmail()) { - $this->redirectIntended(default: route('dashboard', absolute: false)); - - return; + throw $e; } - $user->sendEmailVerificationNotification(); + Auth::user()->update([ + 'password' => Hash::make($validated['password']), + ]); - Session::flash('status', 'verification-link-sent'); + $this->reset('current_password', 'password', 'password_confirmation'); + + $this->dispatch('password-updated'); } public function render() diff --git a/database/migrations/2025_07_28_030305_add_extra_info_to_authentication_tokens.php b/database/migrations/2025_07_28_030305_add_extra_info_to_authentication_tokens.php new file mode 100644 index 0000000..5a91229 --- /dev/null +++ b/database/migrations/2025_07_28_030305_add_extra_info_to_authentication_tokens.php @@ -0,0 +1,31 @@ +string('user_agent')->nullable(); + $table->string('ip')->nullable(); + $table->timestamp('issued_at'); + $table->timestamp('expires_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('authentication_tokens', function (Blueprint $table) { + // + }); + } +}; diff --git a/package-lock.json b/package-lock.json index 8430f37..bd6b802 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "homelab-sso", + "name": "authentikate", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 3663558..5c644a6 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,8 +1,10 @@
- -
+
+
+ +
\ No newline at end of file diff --git a/resources/views/livewire/forms/user-profile.blade.php b/resources/views/livewire/forms/user-profile.blade.php index a9cb4c9..19b6e99 100644 --- a/resources/views/livewire/forms/user-profile.blade.php +++ b/resources/views/livewire/forms/user-profile.blade.php @@ -15,8 +15,12 @@
{{auth()->user()->name}} + @if (!empty(auth()->user()->preferred_username)) {{auth()->user()->preferred_username}} (preferred username) + @else + No preferred username + @endif {{auth()->user()->email}}
diff --git a/resources/views/logged-out.blade.php b/resources/views/logged-out.blade.php new file mode 100644 index 0000000..bcc3ae6 --- /dev/null +++ b/resources/views/logged-out.blade.php @@ -0,0 +1,8 @@ + +
+ You've been logged out of this app + @auth + Back to dashboard + @endauth +
+
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index e6c5587..a833d55 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,6 +38,7 @@ Route::prefix('application/o')->group(function () { Route::post('token', [OIDCController::class, 'token'])->withoutMiddleware(VerifyCsrfToken::class)->name('auth.token'); Route::get('userinfo', [OIDCController::class, 'userinfo'])->name('auth.userinfo'); Route::get('confirm', ConsentScreen::class)->name('auth.confirm'); + Route::get('logout', [OIDCController::class, 'logout'])->name('auth.logout'); }); Route::get('.well-known/jwks.json', [OIDCController::class, 'jwks'])->name('auth.keys'); Route::get('.well-known/openid-configuration', [OIDCController::class, 'openidConfig'])->name('auth.openid-configuration');