From 41e2c43f5d6e860a08ca673df7b470826068b4ad Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 31 Dec 2018 17:00:17 +0200 Subject: [PATCH] allow setting expiration of personal access tokens --- src/Passport.php | 26 ++++++++++++++++++++++++++ src/PassportServiceProvider.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Passport.php b/src/Passport.php index 4a5fae527..25769859a 100644 --- a/src/Passport.php +++ b/src/Passport.php @@ -68,6 +68,13 @@ class Passport */ public static $refreshTokensExpireAt; + /** + * The date when personal access tokens expire. + * + * @var \DateTimeInterface|null + */ + public static $personAccessTokensExpireAt; + /** * The name for API token cookies. * @@ -315,6 +322,25 @@ public static function refreshTokensExpireIn(DateTimeInterface $date = null) return new static; } + /** + * Get or set when personal access tokens expire. + * + * @param \DateTimeInterface|null $date + * @return \DateInterval|static + */ + public static function personalAccessTokensExpireIn(DateTimeInterface $date = null) + { + if (is_null($date)) { + return static::$personAccessTokensExpireAt + ? Carbon::now()->diff(static::$personAccessTokensExpireAt) + : new DateInterval('P1Y'); + } + + static::$personAccessTokensExpireAt = $date; + + return new static; + } + /** * Get or set the name for API token cookies. * diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index bcc7b55d3..3369bbe4d 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -111,7 +111,7 @@ protected function registerAuthorizationServer() ); $server->enableGrantType( - new PersonalAccessGrant, new DateInterval('P1Y') + new PersonalAccessGrant, Passport::personalAccessTokensExpireIn() ); $server->enableGrantType(