dqb78642 2018-11-23 16:38
浏览 109
已采纳

Laravel 5.4 Passport-API无法设置30天到期令牌

I am Using Laravel 5.4 Passport Authentication. I have a problem to set API token expire date for 30 days. I have tried given code in Laravel documentation but it's not working. In the database, it's showing one year default token expiration date.

I have used

public function boot(){

    $this->registerPolicies();

    Passport::routes();

    Passport::tokensExpireIn(Carbon::now()->addDays(30));

}

if there is any solution please suggest me.

Thanks

  • 写回答

1条回答 默认 最新

  • duansao6776 2018-11-23 19:58
    关注

    i also got same issue so.. i used like that

    try to change directly in PassportServiceProvider.php

    go to PassportServiceProvider.php path should be like this

    projectName/vendor/laravel/passport/src/PassportServiceProvider.php
    

    and fine this line

    new PersonalAccessGrant, new DateInterval('P1Y')
    

    for example set expiry 1 month then

    new PersonalAccessGrant, new DateInterval('P1M')
    

    for example set expiry 1 week then

    new PersonalAccessGrant, new DateInterval('P1W')
    

    for example set expiry 5 DAYS then

    new PersonalAccessGrant, new DateInterval('P5D')
    

    for more DateInterval see

    github issue see

    stackoverflow question see

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?