mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 16:52:45 -04:00
- database import: add keep_owners (restore PostgreSQL owners and privileges) and sqlite_database (pick the target SQLite file) to the API, OpenAPI spec, and import form - oauth: require password confirmation and support team selection on OAuth login - remote process: send team broadcast events to the team of the server that ran the process instead of the causer's user id - servers API: handle the legacy build server setting - compose: support parent bind paths and volume driver options - dns: improve record hints and provider management - notifications: fix throttling and missing backup notifications - ui: rework the confirmation modal - add feature and unit tests for the new behavior
107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class OauthSetting extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['provider', 'client_id', 'client_secret', 'redirect_uri', 'tenant', 'base_url', 'enabled', 'custom_label', 'scopes', 'allow_registration', 'auto_join_root_team', 'require_email_verified', 'use_pkce', 'clock_skew_seconds'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'enabled' => 'boolean',
|
|
'allow_registration' => 'boolean',
|
|
'auto_join_root_team' => 'boolean',
|
|
'require_email_verified' => 'boolean',
|
|
'use_pkce' => 'boolean',
|
|
'clock_skew_seconds' => 'integer',
|
|
];
|
|
}
|
|
|
|
protected $hidden = [
|
|
'client_secret',
|
|
];
|
|
|
|
protected function clientSecret(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn (?string $value) => empty($value) ? null : Crypt::decryptString($value),
|
|
set: fn (?string $value) => empty($value) ? null : Crypt::encryptString($value),
|
|
);
|
|
}
|
|
|
|
public function couldBeEnabled(): bool
|
|
{
|
|
switch ($this->provider) {
|
|
case 'azure':
|
|
return filled($this->client_id) && filled($this->client_secret) && filled($this->tenant);
|
|
case 'authentik':
|
|
case 'clerk':
|
|
case 'oidc':
|
|
return filled($this->client_id) && filled($this->client_secret) && filled($this->base_url);
|
|
default:
|
|
return filled($this->client_id) && filled($this->client_secret);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function scopeList(): array
|
|
{
|
|
$scopes = str($this->scopes ?: 'openid email profile')
|
|
->replace(',', ' ')
|
|
->explode(' ')
|
|
->map(fn (string $scope) => trim($scope))
|
|
->filter()
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
|
|
return $scopes === [] ? ['openid', 'email', 'profile'] : $scopes;
|
|
}
|
|
|
|
public function loginLabel(): string
|
|
{
|
|
if (filled($this->custom_label)) {
|
|
return $this->custom_label;
|
|
}
|
|
|
|
$envLabel = config("services.{$this->provider}.custom_label");
|
|
if (filled($envLabel)) {
|
|
return $envLabel;
|
|
}
|
|
|
|
return __("auth.login.{$this->provider}");
|
|
}
|
|
|
|
/**
|
|
* Human-readable provider name, e.g. for "Confirm with Google".
|
|
*/
|
|
public function providerName(): string
|
|
{
|
|
if ($this->isOidc()) {
|
|
return filled($this->custom_label) ? $this->custom_label : 'SSO';
|
|
}
|
|
|
|
return match ($this->provider) {
|
|
'azure' => 'Microsoft',
|
|
'github' => 'GitHub',
|
|
'gitlab' => 'GitLab',
|
|
default => str($this->provider)->headline()->value(),
|
|
};
|
|
}
|
|
|
|
public function isOidc(): bool
|
|
{
|
|
return $this->provider === 'oidc';
|
|
}
|
|
}
|