Compare commits
1
Commits
v1.0.2
...
116129a098
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
116129a098 |
@@ -9,26 +9,26 @@ class DelegateAuthServiceProvider extends ServiceProvider
|
||||
public function register(): void
|
||||
{
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__.'/../config/delegate-auth.php', 'delegate-auth'
|
||||
__DIR__ . "/../config/delegate-auth.php",
|
||||
"delegate-auth",
|
||||
);
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__.'/../config/delegate-auth.php' => config_path('delegate-auth.php'),
|
||||
], 'delegate-auth-config');
|
||||
$this->publishes(
|
||||
[
|
||||
__DIR__ . "/../config/delegate-auth.php" => config_path(
|
||||
"delegate-auth.php",
|
||||
),
|
||||
],
|
||||
"delegate-auth-config",
|
||||
);
|
||||
|
||||
$this->publishes([
|
||||
__DIR__.'/../resources/views/errors/401.blade.php' => resource_path('views/errors/401.blade.php'),
|
||||
], 'delegate-auth-views');
|
||||
|
||||
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
|
||||
$this->loadRoutesFrom(__DIR__ . "/../routes/web.php");
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([
|
||||
Console\InstallCommand::class,
|
||||
]);
|
||||
$this->commands([Console\InstallCommand::class]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,16 +49,22 @@ class DelegateAuthController extends Controller
|
||||
|
||||
private function decryptToken(string $token): ?array
|
||||
{
|
||||
$data = base64_decode(urldecode($token));
|
||||
$payload = openssl_decrypt(
|
||||
substr($data, 16),
|
||||
"AES-256-CBC",
|
||||
config("delegate.encrypt_key"),
|
||||
0,
|
||||
substr($data, 0, 16),
|
||||
);
|
||||
$data = json_decode($payload, associative: true);
|
||||
$data = base64_decode($token, strict: 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);
|
||||
$iv = random_bytes(16);
|
||||
$encrypted = openssl_encrypt(json_encode(['email' => 'user@example.com']), 'AES-256-CBC', $wrongKey, 0, $iv);
|
||||
$token = base64_encode($iv).'.'.$encrypted;
|
||||
$encrypted = openssl_encrypt(json_encode(['email' => 'user@example.com']), 'AES-256-CBC', $wrongKey, OPENSSL_RAW_DATA, $iv);
|
||||
$token = base64_encode($iv.$encrypted);
|
||||
|
||||
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);
|
||||
$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