我尝试使用 Laravel 11 制作 Atlassian Jira Connect 应用程序,但在安装时出现错误

问题描述 投票:0回答:1

我尝试制作 Atlassian Jira Cloud Connect 应用程序,但出现本地错误。错误:安装时未根据请求设置会话存储。

这是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']);
}

}

这是 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);

这是中间件:

<?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
];
}

我要做什么才能让一切顺利进行?我还不熟悉 Laravel 11。

有人可以帮我解决这个案子吗?

XAMPP 上的

ngrok 说:07:42:05.083 EESTPOST /rtc/public/installed 419 未知状态

laravel jira
1个回答
0
投票

新思维,

我自己解决了问题。

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();

和控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Tenant;
use Illuminate\Support\Facades\Log;

InstallationController 类扩展了 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']);
}
}

还有 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']);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.