I just read the https://laravel.com/docs/5.6/passport documentation and I have some doubts that hopefully someone could help me with:
First, some context, I want to
Tackling Question 5
Finally, there are a lot of endpoints that I get from passport that I don't think I will use for example:
oauth/clients*
,oauth/personal-access-tokens*
is there a way to remove them from the endpoints published by passport?
Passport::routes($callback = null, array $options = [])
takes an optional $callback
function and optional $options
argument.
The callback function takes a $router
argument from which you can then choose which routes to install as shown below in your AuthServiceProvider.php
that is enabling a more granular configuration:
Passport::routes(function ($router) {
$router->forAccessTokens();
$router->forPersonalAccessTokens();
$router->forTransientTokens();
});
Passport::tokensExpireIn(Carbon::now()->addMinutes(10));
Passport::refreshTokensExpireIn(Carbon::now()->addDays(10));
This way we only create the passport routes that we need.
forAccessTokens()
; enable us to create access tokens.
forPersonalAccessTokens()
; enable us to create personal tokens although we will not use this in this article. Lastly,
forTransientTokens()
; creates the route for refreshing tokens.
If you run php artisan route:list
you can see the new endpoints installed by Laravel Passport.
| POST | oauth/token | \Laravel\Passport\Http\Controllers\AccessTokenController@issueToken
| POST | oauth/token/refresh | \Laravel\Passport\Http\Controllers\TransientTokenController@refresh