You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
987 B
31 lines
987 B
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Laravel\Passport\Passport;
|
|
use League\OAuth2\Server\AuthorizationServer;
|
|
use Laravel\Passport\Bridge\UserRepository;
|
|
use Laravel\Passport\Bridge\RefreshTokenRepository;
|
|
use DateInterval;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
protected $policies = [];
|
|
|
|
public function boot(): void
|
|
{
|
|
Passport::tokensExpireIn(now()->addHour());
|
|
Passport::refreshTokensExpireIn(now()->addMonth());
|
|
|
|
$this->app->afterResolving(AuthorizationServer::class, function ($server) {
|
|
$grant = new \League\OAuth2\Server\Grant\PasswordGrant(
|
|
app(UserRepository::class),
|
|
app(RefreshTokenRepository::class)
|
|
);
|
|
$grant->setRefreshTokenTTL(new DateInterval('P1M')); // 1 tháng
|
|
|
|
$server->enableGrantType($grant, new DateInterval('PT1H')); // 1 giờ
|
|
});
|
|
}
|
|
}
|
|
|