Skip to content

Commit

Permalink
Added way to generate signed url for horizon request
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnesselr committed Dec 9, 2023
1 parent 3cb322b commit 878af76
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/Console/Commands/MakeHorizonSignedUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\URL;

class MakeHorizonSignedUrl extends Command
{
protected $signature = 'denhac:make-horizon-signed-url';

protected $description = 'Create a signed URL to populate the secret cookie and get access to horizon';

public function handle()
{
$url = URL::temporarySignedRoute('horizon-signed-url', now()->addMinutes(5));
$this->info($url);
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/HorizonSignedUrlController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Cookie;

class HorizonSignedUrlController extends Controller
{
public function __invoke(Request $request)
{
if (! $request->hasValidSignature()) {
abort(401);
}

return response("success")->cookie(Cookie::create(
'horizon',
setting('horizon.password'),
now()->addYears(5) // It's annoying to generate again when you need it. Access is revoked for everyone by changing the password.
));
}
}
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
|
*/

use App\Http\Controllers\HorizonSignedUrlController;
use App\Http\Controllers\SlackEventController;
use App\Http\Controllers\SlackInteractivityController;
use App\Http\Controllers\SlackMembershipCommandController;
Expand All @@ -36,3 +37,5 @@
Route::get('success', [App\Http\Controllers\Quickbooks\RedirectController::class, 'success']);
Route::get('fail', [App\Http\Controllers\Quickbooks\RedirectController::class, 'fail']);
});

Route::get('/horizon-signed-url', HorizonSignedUrlController::class)->name('horizon-signed-url');

0 comments on commit 878af76

Please sign in to comment.