configure auth cookies
This commit is contained in:
parent
db18fae479
commit
4ee20396e8
3 changed files with 77 additions and 6 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Auth\AuthCookieSettings;
|
||||
use App\Auth\BcryptPasswordHasher;
|
||||
use App\Auth\Clock;
|
||||
use App\Auth\PasswordHasher;
|
||||
|
|
@ -32,5 +33,45 @@ class AppServiceProvider extends ServiceProvider
|
|||
Filesystem::class,
|
||||
LaravelFilesystem::class,
|
||||
);
|
||||
$this->app->bind(
|
||||
AuthCookieSettings::class,
|
||||
function (): AuthCookieSettings {
|
||||
$secureCookie = config('session.secure');
|
||||
$sessionDomain = config('session.domain');
|
||||
$sameSite = config('session.same_site');
|
||||
|
||||
return new AuthCookieSettings(
|
||||
secure: $this->booleanConfig($secureCookie),
|
||||
domain: $this->nullableStringConfig($sessionDomain),
|
||||
sameSite: is_string($sameSite) ? $sameSite : 'lax',
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function booleanConfig(mixed $value): bool
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
return $value === 1;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
return in_array(strtolower($value), ['1', 'true'], true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function nullableStringConfig(mixed $value): ?string
|
||||
{
|
||||
if (! is_string($value) || trim($value) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue