Skip to content

Commit

Permalink
feat: 🛂 integrate Authentik authentication with Coolify
Browse files Browse the repository at this point in the history
- Configured Authentik as the OAuth provider in Coolify.
  • Loading branch information
danilomartinelli committed Oct 11, 2024
1 parent ca2d946 commit f0c8849
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Livewire/SettingsOauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected function rules()
$carry["oauth_settings_map.$setting->provider.client_secret"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.redirect_uri"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.tenant"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.base_url"] = 'nullable';

return $carry;
}, []);
Expand Down
1 change: 1 addition & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EventServiceProvider extends ServiceProvider
],
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
\SocialiteProviders\Azure\AzureExtendSocialite::class.'@handle',
\SocialiteProviders\Authentik\AuthentikExtendSocialite::class.'@handle',
],
ProxyStarted::class => [
ProxyStartedNotification::class,
Expand Down
11 changes: 11 additions & 0 deletions bootstrap/helpers/socialite.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ function get_socialite_provider(string $provider)
return Socialite::driver('azure')->setConfig($azure_config);
}

if ($provider == 'authentik') {
$authentik_config = new \SocialiteProviders\Manager\Config(
$oauth_setting->client_id,
$oauth_setting->client_secret,
$oauth_setting->redirect_uri,
['base_url' => $oauth_setting->base_url],
);

return Socialite::driver('authentik')->setConfig($authentik_config);
}

$config = [
'client_id' => $oauth_setting->client_id,
'client_secret' => $oauth_setting->client_secret,
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"pusher/pusher-php-server": "^7.2",
"resend/resend-laravel": "^0.13.0",
"sentry/sentry-laravel": "^4.6",
"socialiteproviders/authentik": "^5.2",
"socialiteproviders/microsoft-azure": "^5.1",
"spatie/laravel-activitylog": "^4.7.3",
"spatie/laravel-data": "^3.4.3",
Expand Down
50 changes: 50 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@
'tenant' => env('AZURE_TENANT_ID'),
'proxy' => env('AZURE_PROXY'),
],

'authentik' => [
'base_url' => env('AUTHENTIK_BASE_URL'),
'client_id' => env('AUTHENTIK_CLIENT_ID'),
'client_secret' => env('AUTHENTIK_CLIENT_SECRET'),
'redirect' => env('AUTHENTIK_REDIRECT_URI'),
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('oauth_settings', function (Blueprint $table) {
Schema::table('oauth_settings', function (Blueprint $table) {
$table->string('base_url')->nullable();
});
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('oauth_settings', function (Blueprint $table) {
Schema::table('oauth_settings', function (Blueprint $table) {
$table->dropColumn('base_url');
});
});
}
};
4 changes: 4 additions & 0 deletions database/seeders/OauthSettingSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ public function run(): void
'id' => 4,
'provider' => 'google',
]);
OauthSetting::firstOrCreate([
'id' => 5,
'provider' => 'authentik',
]);
}
}
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"auth.login": "Login",
"auth.login.authentik": "Login with Authentik",
"auth.login.azure": "Login with Microsoft",
"auth.login.bitbucket": "Login with Bitbucket",
"auth.login.github": "Login with GitHub",
Expand Down
4 changes: 4 additions & 0 deletions resources/views/livewire/settings-oauth.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<x-forms.input id="oauth_settings_map.{{ $oauth_setting->provider }}.tenant"
label="Tenant" />
@endif
@if ($oauth_setting->provider == 'authentik')
<x-forms.input id="oauth_settings_map.{{ $oauth_setting->provider }}.base_url"
label="Base URL" />
@endif
</div>
</div>
@endforeach
Expand Down

0 comments on commit f0c8849

Please sign in to comment.