I try to make Atlassian Jira Cloud Connect App but I get error local.ERROR: Session store not set on request on installation.
Here is InstallationController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Tenant;
use Illuminate\Support\Facades\Log;
class InstallationController extends Controller
{
public function store(Request $request)
{
// Store tenant details for later use (e.g., in a database)
$clientKey = $request->input('clientKey'); // Assuming 'clientKey' is sent by Jira Cloud
$baseUrl = $request->input('baseUrl');
// Log the installation request
Log::info('Received installation request', var_export($request->all()));
// Your logic to store tenant details goes here
$tenant = new Tenant();
$tenant->client_key = $clientKey;
$tenant->base_url = $baseUrl;
// Add more fields as needed
try {
// Save tenant details
$tenant->save();
} catch (\Exception $e) {
Log::error('Failed to save tenant details: ' . $e->getMessage());
return response()->json(['status' => 'error', 'message' => 'Failed to save tenant details'], 500);
}
// Respond with a success JSON response
return response()->json(['status' => 'ok']);
}
}
And here is web.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Models\Tenant;
use App\Http\Controllers\InstallationController;
use App\Http\Middleware\VerifyCsrfToken;
Route::get('/', function () {
return view('welcome');
});
Route::post('/installed', [InstallationController::class, 'store'])
->middleware(VerifyCsrfToken::class);
And here is Middleware:
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'/rtc/public/installed', // Add your installation endpoint here
];
}
What I do to get everything work? I am not yet familiar with Laravel 11.
So anyone can help me on this case?
ngrok on XAMPP says this: 07:42:05.083 EESTPOST /rtc/public/installed 419 unknown status
Newer-mind,
I solved problem my self.
bootstrap/app.php
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Laravel\Sanctum\Http\Middleware\CheckAbilities;
use Laravel\Sanctum\Http\Middleware\CheckForAnyAbility;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->statefulApi();
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
And controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Tenant;
use Illuminate\Support\Facades\Log;
class InstallationController extends Controller {
public function store(Request $request)
{
// Store tenant details for later use (e.g., in a database)
//$clientKey = $request->input('clientKey'); // Assuming 'clientKey' is sent by Jira Cloud
//$baseUrl = $request->input('baseUrl');
$result = json_decode(file_get_contents('php://input'));
// Your logic to store tenant details goes here
$tenant = new Tenant();
$tenant->client_key = file_get_contents('php://input');
$tenant->base_url = $result->baseUrl;
// Add more fields as needed
try {
// Save tenant details
$tenant->save();
} catch (\Exception $e) {
Log::error('Failed to save tenant details: ' . $e->getMessage());
return response()->json(['status' => 'error', 'message' => 'Failed to save tenant details'], 500);
}
// Respond with a success JSON response
return response()->json(['status' => 'ok']);
}
}
And api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\InstallationController;
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:sanctum');
Route::post('/installed', [InstallationController::class, 'store']);