Skip to content

Commit 21099f1

Browse files
authored
feat: allow token "expires in" to be defined as date interval (#1733)
1 parent e8af499 commit 21099f1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/Passport.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -288,50 +288,56 @@ public static function tokensCan(array $scopes)
288288
/**
289289
* Get or set when access tokens expire.
290290
*
291-
* @param \DateTimeInterface|null $date
291+
* @param \DateTimeInterface|\DateInterval|null $date
292292
* @return \DateInterval|static
293293
*/
294-
public static function tokensExpireIn(DateTimeInterface $date = null)
294+
public static function tokensExpireIn(DateTimeInterface|DateInterval $date = null)
295295
{
296296
if (is_null($date)) {
297297
return static::$tokensExpireIn ?? new DateInterval('P1Y');
298298
}
299299

300-
static::$tokensExpireIn = Carbon::now()->diff($date);
300+
static::$tokensExpireIn = $date instanceof DateTimeInterface
301+
? Carbon::now()->diff($date)
302+
: $date;
301303

302304
return new static;
303305
}
304306

305307
/**
306308
* Get or set when refresh tokens expire.
307309
*
308-
* @param \DateTimeInterface|null $date
310+
* @param \DateTimeInterface|\DateInterval|null $date
309311
* @return \DateInterval|static
310312
*/
311-
public static function refreshTokensExpireIn(DateTimeInterface $date = null)
313+
public static function refreshTokensExpireIn(DateTimeInterface|DateInterval $date = null)
312314
{
313315
if (is_null($date)) {
314316
return static::$refreshTokensExpireIn ?? new DateInterval('P1Y');
315317
}
316318

317-
static::$refreshTokensExpireIn = Carbon::now()->diff($date);
319+
static::$refreshTokensExpireIn = $date instanceof DateTimeInterface
320+
? Carbon::now()->diff($date)
321+
: $date;
318322

319323
return new static;
320324
}
321325

322326
/**
323327
* Get or set when personal access tokens expire.
324328
*
325-
* @param \DateTimeInterface|null $date
329+
* @param \DateTimeInterface|\DateInterval|null $date
326330
* @return \DateInterval|static
327331
*/
328-
public static function personalAccessTokensExpireIn(DateTimeInterface $date = null)
332+
public static function personalAccessTokensExpireIn(DateTimeInterface|DateInterval $date = null)
329333
{
330334
if (is_null($date)) {
331335
return static::$personalAccessTokensExpireIn ?? new DateInterval('P1Y');
332336
}
333337

334-
static::$personalAccessTokensExpireIn = Carbon::now()->diff($date);
338+
static::$personalAccessTokensExpireIn = $date instanceof DateTimeInterface
339+
? Carbon::now()->diff($date)
340+
: $date;
335341

336342
return new static;
337343
}

0 commit comments

Comments
 (0)