1

I am using Laravel Passport for token authentication and facing an issue where $tokenResult is null. I suspect the default rate limit (throttle:60,1) is exceeded, so I temporarily modified the vendor\laravel\passport\routes\web.php file:

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

However, modifying the vendor directory is not a good practice. I am looking for an alternative solution.

Current Code:

$data = [ 
    'username' => $request->mobileNo,
    'password' => $randomPassword,
    'client_id' => $oauthClient->id,
    'client_secret' => $oauthClient->secret,
    'grant_type' => 'password',
];
$request = app('request')->create('/oauth/token', 'POST', $data);
$tokenResult = json_decode(app()->handle($request)->getContent());

Instead of modifying vendor, publish Passport's routes and override them.

If dynamic configuration is needed, adjust the throttle settings in App\Providers\RouteServiceProvider

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.