Skip to content

Commit e7e7cc1

Browse files
committed
feat: integrate OAuth authentication with GitHub and Keycloak
This commit adds the option to enable OAuth authentication through Github / Keycloak. This requires additional configuration from the user. This configuration is exposed through a set of new environment variables. It currently does not support any kind of roles / group management. This must be managed either trough the domain allowlist or on the provider side. All newly registered users are normal users and may be promoted though the web portal as necessary. Implements #264
1 parent 5f1043d commit e7e7cc1

12 files changed

Lines changed: 163 additions & 6 deletions

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"php": "^8.2",
2323
"ext-simplexml": "*",
2424
"doctrine/dbal": "^3.6",
25+
"dutchcodingcompany/filament-socialite": "^3.1",
2526
"filament/filament": "^4.0",
2627
"filament/spatie-laravel-settings-plugin": "^4.0",
2728
"guzzlehttp/guzzle": "^7.8",
@@ -33,6 +34,7 @@
3334
"illuminate/support": "^11.35.0",
3435
"laravel/sanctum": "^4.0",
3536
"nesbot/carbon": "^2.70",
37+
"socialiteproviders/keycloak": "^5.3",
3638
"spatie/laravel-data": "^4.11",
3739
"spatie/laravel-query-builder": "^5.5",
3840
"spatie/laravel-settings": "^3.2",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::create('socialite_users', function (Blueprint $table) {
11+
$table->id();
12+
13+
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
14+
$table->string('provider');
15+
$table->string('provider_id');
16+
17+
$table->timestamps();
18+
19+
$table->unique([
20+
'provider',
21+
'provider_id',
22+
]);
23+
});
24+
25+
}
26+
27+
public function down()
28+
{
29+
Schema::dropIfExists('socialite_users');
30+
}
31+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::table('users', function (Blueprint $table) {
11+
$table->string('password')->nullable()->change();
12+
});
13+
14+
}
15+
16+
public function down()
17+
{
18+
Schema::table('users', function (Blueprint $table) {
19+
$table->string('password')->nullable(false)->change();
20+
});
21+
}
22+
};

public/build/assets/cachet-BQ3AZC_V.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/build/assets/cachet-cq60tD7N.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/theme-Bpp5vRLw.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/theme-CA1Ilmhs.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/build/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"resources/css/cachet.css": {
3-
"file": "assets/cachet-BQ3AZC_V.css",
3+
"file": "assets/cachet-cq60tD7N.css",
44
"src": "resources/css/cachet.css",
55
"isEntry": true
66
},
77
"resources/css/dashboard/theme.css": {
8-
"file": "assets/theme-CA1Ilmhs.css",
8+
"file": "assets/theme-Bpp5vRLw.css",
99
"src": "resources/css/dashboard/theme.css",
1010
"isEntry": true
1111
},

src/CachetDashboardServiceProvider.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Cachet\Filament\Pages\EditProfile;
66
use Cachet\Http\Middleware\SetAppLocale;
77
use Cachet\Settings\AppSettings;
8+
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
9+
use DutchCodingCompany\FilamentSocialite\Provider;
810
use Filament\FontProviders\LocalFontProvider;
911
use Filament\Http\Middleware\Authenticate;
1012
use Filament\Http\Middleware\DisableBladeIconComponents;
@@ -106,6 +108,17 @@ public function panel(Panel $panel): Panel
106108
->path(Cachet::dashboardPath())
107109
->bootUsing(function (): void {
108110
Section::configureUsing(fn (Section $section) => $section->columnSpanFull());
109-
});
111+
})
112+
->plugin(FilamentSocialitePlugin::make()->providers(
113+
collect([
114+
config('services.github.client_id') ? Provider::make('github') : null,
115+
config('services.keycloak.client_id') ? Provider::make('keycloak') : null,
116+
])->filter()->values()->all()
117+
)
118+
->rememberLogin(config('services.oauth.rememberLogin', false))
119+
->registration(config('services.oauth.registration', false))
120+
->domainAllowList(config('services.oauth.domainAllowlist', []))
121+
->userModelClass(config('cachet.user_model'))
122+
);
110123
}
111124
}

workbench/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ VITE_PUSHER_PORT="${PUSHER_PORT}"
5858
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
5959
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
6060

61+
GITHUB_CLIENT_ID=
62+
GITHUB_CLIENT_SECRET=
63+
64+
KEYCLOAK_CLIENT_ID=
65+
KEYCLOAK_CLIENT_SECRET=
66+
KEYCLOAK_REALM="master"
67+
KEYCLOAK_BASE_URL=
68+
69+
OAUTH_REMEMBER_LOGIN=
70+
OAUTH_REGISTRATION=
71+
OAUTH_DOMAIN_ALLOWLIST=

0 commit comments

Comments
 (0)