How to use Laravel Passport with Password Grant Tokens?

前端 未结 2 986
一向
一向 2020-12-01 07:04

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

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 07:31

    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
    

提交回复
热议问题