1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

RuntimeException: Session store not set on request. in laravel passport

Discussão em 'Outras Linguagens' iniciado por alireza.haraji.dev, Novembro 5, 2024 às 10:52.

  1. this my composer require laravel app

    "php": "^8.1",
    "guzzlehttp/guzzle": "^7.2",
    "laravel/framework": "^10.10",
    "laravel/passport": "^12.3",
    "laravel/sanctum": "^3.3",
    "laravel/tinker": "^2.8"


    and this my routes in api.php file

    Route::prefix('v1')->group(function () {

    // Regitser user API
    Route::post('register', [RegisterController::class, 'register'])->name('api.register');


    // API for user active email
    Route::get('activation/{token}', [RegisterController::class, 'signupActive'])->name('api.signupActive');

    // API for user login
    Route::post('login', [LoginController::class, 'login'])->name('api.login');

    // Private Routes
    Route::middleware("auth:api")->group(function () {

    // Show user profile
    Route::get('profile', [LoginController::class, 'profile'])->name('api.profile');
    });

    // fix error login not found
    Route::get('login_error', function () {
    return response()->json([
    'message' => 'Unauthenticated.'
    ],401);
    })->name('login');

    // predefined passport routes
    Route::group([
    'namespace' => '\Laravel\Passport\Http\Controllers',
    'prefix' => 'oauth',
    ], function () {

    Route::post('/token', [
    'uses' => 'AccessTokenController@issueToken',
    'as' => 'token',
    'middleware' => 'throttle',
    ]);

    Route::get('/authorize', [
    'uses' => 'AuthorizationController@authorize',
    'as' => 'authorizations.authorize',
    'middleware' => 'api',
    ]);

    $guard = config('passport.guard', null);

    Route::middleware(['web', $guard ? 'auth:'.$guard : 'auth'])->group(function () {
    Route::post('/token/refresh', [
    'uses' => 'TransientTokenController@refresh',
    'as' => 'token.refresh',
    ]);

    Route::post('/authorize', [
    'uses' => 'ApproveAuthorizationController@approve',
    'as' => 'authorizations.approve',
    ]);

    Route::delete('/authorize', [
    'uses' => 'DenyAuthorizationController@deny',
    'as' => 'authorizations.deny',
    ]);

    Route::get('/tokens', [
    'uses' => 'AuthorizedAccessTokenController@forUser',
    'as' => 'tokens.index',
    ]);

    Route::delete('/tokens/{token_id}', [
    'uses' => 'AuthorizedAccessTokenController@destroy',
    'as' => 'tokens.destroy',
    ]);

    Route::get('/clients', [
    'uses' => 'ClientController@forUser',
    'as' => 'clients.index',
    ]);

    Route::post('/clients', [
    'uses' => 'ClientController@store',
    'as' => 'clients.store',
    ]);

    Route::put('/clients/{client_id}', [
    'uses' => 'ClientController@update',
    'as' => 'clients.update',
    ]);


    when i request to ouauth/authorize or other routes i get this error:

    RuntimeException: Session store not set on request. in file C:\PHP\rest-api-backend\vendor\laravel\framework\src\Illuminate\Http\Request.php on line 560


    I don`t want my app auth session base and web so i change guard to=> 'api' in config/passport.php file and i get this error:

    TypeError: Laravel\Passport\Http\Controllers\AuthorizationController::__construct(): Argument #2 ($guard) must be of type Illuminate\Contracts\Auth\StatefulGuard, Laravel\Passport\Guards\TokenGuard given in file C:\PHP\rest-api-backend\vendor\laravel\passport\src\Http\Controllers\AuthorizationController.php on line 52

    Continue reading...

Compartilhe esta Página