Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
116129a098 |
@@ -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,16 +49,22 @@ class DelegateAuthController extends Controller
|
|||||||
|
|
||||||
private function decryptToken(string $token): ?array
|
private function decryptToken(string $token): ?array
|
||||||
{
|
{
|
||||||
$data = base64_decode(urldecode($token));
|
$data = base64_decode($token, strict: true);
|
||||||
$payload = openssl_decrypt(
|
|
||||||
substr($data, 16),
|
|
||||||
"AES-256-CBC",
|
|
||||||
config("delegate.encrypt_key"),
|
|
||||||
0,
|
|
||||||
substr($data, 0, 16),
|
|
||||||
);
|
|
||||||
$data = json_decode($payload, associative: true);
|
|
||||||
|
|
||||||
return is_array($data) ? $data : null;
|
if ($data === false || strlen($data) <= 16) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = substr(hash('sha256', config('delegate-auth.encrypt_key'), binary: true), 0, 32);
|
||||||
|
|
||||||
|
$payload = openssl_decrypt(substr($data, 16), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, substr($data, 0, 16));
|
||||||
|
|
||||||
|
if ($payload === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode($payload, associative: true);
|
||||||
|
|
||||||
|
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