Laravel Passport token lifetime

前端 未结 10 1428
轮回少年
轮回少年 2021-01-04 01:12

I don\'t get what I\'m doing wrong. I can\'t set token expiration time.



        
10条回答
  •  暖寄归人
    2021-01-04 01:48

    File: AuthServiceProvider.php

    Add these lines

    use Laravel\Passport\Bridge\PersonalAccessGrant;
    use League\OAuth2\Server\AuthorizationServer;
    

    Add the following code in boot function

    public function boot() {
         Passport::routes();
         $lifetime = new \DateInterval('PT24H'); // For 24hours
    
         $this->app->get(AuthorizationServer::class)->enableGrantType(new PersonalAccessGrant(), $lifetime);
    }
    

提交回复
热议问题