@julianov If you’re going to use Passport then please read its docs.
Passport is an OAuth server implementation. You use it to request OAuth tokens. The docs also cover using scopes.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to perform user authorization and for this I have decided to implement it with passport. I will not use sanctum because passport gives me the possibility of scalability in the future.
So, to create a new token I do it whit this simple line:
'token' => $user->createToken("user_token")->accessToken
So whit that I implements meddleware to authenticate a user for same url
Route::middleware('auth:authentication')->post('/v0/testroute', 'App\Http\Controllers\UserController@test');
But how can I use roles with tokens? For example if I create an scope for some user
$token = $user->createToken("user_token", ['admin'])->accessToken;
How Can I protect the url with that scope? I mean only users with the scope can enter the url
Route::middleware('auth:authentication','admin')->post('/v0/testroute', 'App\Http\Controllers\UserController@test');
It's that right?
Please or to participate in this conversation.