Skip to content

Commit 670a358

Browse files
authored
Merge pull request #919 from themsaid/pr/17149
Allow setting expiration of personal access tokens
2 parents eab9433 + 41e2c43 commit 670a358

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Passport.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class Passport
6868
*/
6969
public static $refreshTokensExpireAt;
7070

71+
/**
72+
* The date when personal access tokens expire.
73+
*
74+
* @var \DateTimeInterface|null
75+
*/
76+
public static $personAccessTokensExpireAt;
77+
7178
/**
7279
* The name for API token cookies.
7380
*
@@ -315,6 +322,25 @@ public static function refreshTokensExpireIn(DateTimeInterface $date = null)
315322
return new static;
316323
}
317324

325+
/**
326+
* Get or set when personal access tokens expire.
327+
*
328+
* @param \DateTimeInterface|null $date
329+
* @return \DateInterval|static
330+
*/
331+
public static function personalAccessTokensExpireIn(DateTimeInterface $date = null)
332+
{
333+
if (is_null($date)) {
334+
return static::$personAccessTokensExpireAt
335+
? Carbon::now()->diff(static::$personAccessTokensExpireAt)
336+
: new DateInterval('P1Y');
337+
}
338+
339+
static::$personAccessTokensExpireAt = $date;
340+
341+
return new static;
342+
}
343+
318344
/**
319345
* Get or set the name for API token cookies.
320346
*

src/PassportServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function registerAuthorizationServer()
111111
);
112112

113113
$server->enableGrantType(
114-
new PersonalAccessGrant, new DateInterval('P1Y')
114+
new PersonalAccessGrant, Passport::personalAccessTokensExpireIn()
115115
);
116116

117117
$server->enableGrantType(

0 commit comments

Comments
 (0)