Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
116129a098 | ||
|
|
470596e0b4 |
@@ -1,59 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="fr">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>401 – Accès non autorisé</title>
|
|
||||||
<style>
|
|
||||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
||||||
background: #f8fafc;
|
|
||||||
color: #1e293b;
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid #e2e8f0;
|
|
||||||
border-radius: 12px;
|
|
||||||
padding: 2.5rem 3rem;
|
|
||||||
max-width: 420px;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
box-shadow: 0 4px 24px rgba(0,0,0,.06);
|
|
||||||
}
|
|
||||||
|
|
||||||
.code {
|
|
||||||
font-size: 4rem;
|
|
||||||
font-weight: 700;
|
|
||||||
color: #e11d48;
|
|
||||||
line-height: 1;
|
|
||||||
margin-bottom: .5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
font-weight: 600;
|
|
||||||
margin-bottom: .75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
font-size: .95rem;
|
|
||||||
color: #64748b;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="card">
|
|
||||||
<div class="code">401</div>
|
|
||||||
<h1>Accès non autorisé</h1>
|
|
||||||
<p>{{ $exception->getMessage() ?: 'Vous n\'êtes pas autorisé à accéder à cette ressource.' }}</p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -9,26 +9,26 @@ class DelegateAuthServiceProvider extends ServiceProvider
|
|||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(
|
$this->mergeConfigFrom(
|
||||||
__DIR__.'/../config/delegate-auth.php', 'delegate-auth'
|
__DIR__ . "/../config/delegate-auth.php",
|
||||||
|
"delegate-auth",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
$this->publishes([
|
$this->publishes(
|
||||||
__DIR__.'/../config/delegate-auth.php' => config_path('delegate-auth.php'),
|
[
|
||||||
], 'delegate-auth-config');
|
__DIR__ . "/../config/delegate-auth.php" => config_path(
|
||||||
|
"delegate-auth.php",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
"delegate-auth-config",
|
||||||
|
);
|
||||||
|
|
||||||
$this->publishes([
|
$this->loadRoutesFrom(__DIR__ . "/../routes/web.php");
|
||||||
__DIR__.'/../resources/views/errors/401.blade.php' => resource_path('views/errors/401.blade.php'),
|
|
||||||
], 'delegate-auth-views');
|
|
||||||
|
|
||||||
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
|
|
||||||
|
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->commands([
|
$this->commands([Console\InstallCommand::class]);
|
||||||
Console\InstallCommand::class,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,31 +49,22 @@ class DelegateAuthController extends Controller
|
|||||||
|
|
||||||
private function decryptToken(string $token): ?array
|
private function decryptToken(string $token): ?array
|
||||||
{
|
{
|
||||||
if (!str_contains($token, ".")) {
|
$data = base64_decode($token, strict: true);
|
||||||
|
|
||||||
|
if ($data === false || strlen($data) <= 16) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[$ivB64, $encrypted] = explode(".", $token, 2);
|
$key = substr(hash('sha256', config('delegate-auth.encrypt_key'), binary: true), 0, 32);
|
||||||
|
|
||||||
$iv = base64_decode($ivB64, strict: true);
|
$payload = openssl_decrypt(substr($data, 16), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, substr($data, 0, 16));
|
||||||
$key = substr(
|
|
||||||
hash("sha256", config("delegate-auth.encrypt_key"), binary: true),
|
|
||||||
0,
|
|
||||||
32,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($iv === false || strlen($iv) !== 16) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$payload = openssl_decrypt($encrypted, "AES-256-CBC", $key, 0, $iv);
|
|
||||||
|
|
||||||
if ($payload === false) {
|
if ($payload === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($payload, associative: true);
|
$decoded = json_decode($payload, associative: true);
|
||||||
|
|
||||||
return is_array($data) ? $data : null;
|
return is_array($decoded) ? $decoded : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ class LoginTest extends TestCase
|
|||||||
{
|
{
|
||||||
$wrongKey = substr(hash('sha256', 'wrong-key', binary: true), 0, 32);
|
$wrongKey = substr(hash('sha256', 'wrong-key', binary: true), 0, 32);
|
||||||
$iv = random_bytes(16);
|
$iv = random_bytes(16);
|
||||||
$encrypted = openssl_encrypt(json_encode(['email' => 'user@example.com']), 'AES-256-CBC', $wrongKey, 0, $iv);
|
$encrypted = openssl_encrypt(json_encode(['email' => 'user@example.com']), 'AES-256-CBC', $wrongKey, OPENSSL_RAW_DATA, $iv);
|
||||||
$token = base64_encode($iv).'.'.$encrypted;
|
$token = base64_encode($iv.$encrypted);
|
||||||
|
|
||||||
User::create(['email' => 'user@example.com']);
|
User::create(['email' => 'user@example.com']);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -39,8 +39,8 @@ abstract class TestCase extends OrchestraTestCase
|
|||||||
{
|
{
|
||||||
$key = substr(hash('sha256', config('delegate-auth.encrypt_key'), binary: true), 0, 32);
|
$key = substr(hash('sha256', config('delegate-auth.encrypt_key'), binary: true), 0, 32);
|
||||||
$iv = random_bytes(16);
|
$iv = random_bytes(16);
|
||||||
$encrypted = openssl_encrypt(json_encode($payload), 'AES-256-CBC', $key, 0, $iv);
|
$encrypted = openssl_encrypt(json_encode($payload), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
return base64_encode($iv).'.'.$encrypted;
|
return base64_encode($iv.$encrypted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user