Laravel 5.8 Passport oAuth 2.0 Usage and Implementation

STEP 1: Implementation
You must follow the steps as explained in the documentation.
It provides the following grant types out of the box. Laravel passport with password grant tokens
1- Implicit Grant Tokens: Used when your app/website needs to use data from client’s profile or account (mostly). Like signup using facebook. Or posting something on facebook from a 3rd party.
2- Client Credentials Grant Tokens: The client credentials grant is suitable for machine-to-machine authentication. can be generated only from the command line.
3- Personal Access Tokens: Sometimes, your users may want to issue access tokens to themselves without going through the typical authorization code redirect flow as mentioned in (1).
4- Modified Client_Credentials Token: I wanted the users to sign up and communicate between machine to machine, without the involvement of any mediator and put a possible subscription as well, all while keeping the original settings intact and avoid the problem and solving the error.

STEP 2: Needed Modifications
Now, move all the api.php routes associated with client credential out of:
and move them into a new route file named:
doing this makes sure nothing of the core functionality is affected.
Next, we need to use this new route file (client_credentials.php). To do this, update:
by adding a new method and calling it in the existing “map” method as shown below in file RouteServiceProvider.php

    // ref new method for adding client credentials

// new client credentials method
protected function mapClientCredentialRoutes()
Route::prefix(‘api’) // I still want /api/ urls
->middleware(‘client_credentials’) // new middleware I’ll set up in a bit
->group(base_path(‘routes/client_credentials.php’)); // referencing my new routes file
Now modify the kernel file to allow above file to be part of the routing system.
Here create a new middleware group for client_credentials for our new middleware.
// \Illuminate\Session\Middleware\AuthenticateSession::class,
‘api’ => [

    // NEW LINE
    'client_credentials' => [

Now for the usage part.
Create a new client credential from the default vue component

Secret keys to be used only in PHP server-side scripting
Implement the functions as follows.

use App\User;
use Illuminate\Http\Request;

Route::middleware(‘client_credentials’)->get(‘/user’, function (Request $request) {
return response()->json([“data”=>true]);
Route::middleware(‘client_credentials’)->get(‘/user/get’, function(Request $request){
$user_id = $request->get(“uid”);
$user = User::where(‘id’,’=’,$user_id)->get()->first();
return response()->json($user);