Skip to content

Commit

Permalink
feat: allow token "expires in" to be defined as date interval (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmllr95 authored Mar 21, 2024
1 parent e8af499 commit 21099f1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,50 +288,56 @@ public static function tokensCan(array $scopes)
/**
* Get or set when access tokens expire.
*
* @param \DateTimeInterface|null $date
* @param \DateTimeInterface|\DateInterval|null $date
* @return \DateInterval|static
*/
public static function tokensExpireIn(DateTimeInterface $date = null)
public static function tokensExpireIn(DateTimeInterface|DateInterval $date = null)
{
if (is_null($date)) {
return static::$tokensExpireIn ?? new DateInterval('P1Y');
}

static::$tokensExpireIn = Carbon::now()->diff($date);
static::$tokensExpireIn = $date instanceof DateTimeInterface
? Carbon::now()->diff($date)
: $date;

return new static;
}

/**
* Get or set when refresh tokens expire.
*
* @param \DateTimeInterface|null $date
* @param \DateTimeInterface|\DateInterval|null $date
* @return \DateInterval|static
*/
public static function refreshTokensExpireIn(DateTimeInterface $date = null)
public static function refreshTokensExpireIn(DateTimeInterface|DateInterval $date = null)
{
if (is_null($date)) {
return static::$refreshTokensExpireIn ?? new DateInterval('P1Y');
}

static::$refreshTokensExpireIn = Carbon::now()->diff($date);
static::$refreshTokensExpireIn = $date instanceof DateTimeInterface
? Carbon::now()->diff($date)
: $date;

return new static;
}

/**
* Get or set when personal access tokens expire.
*
* @param \DateTimeInterface|null $date
* @param \DateTimeInterface|\DateInterval|null $date
* @return \DateInterval|static
*/
public static function personalAccessTokensExpireIn(DateTimeInterface $date = null)
public static function personalAccessTokensExpireIn(DateTimeInterface|DateInterval $date = null)
{
if (is_null($date)) {
return static::$personalAccessTokensExpireIn ?? new DateInterval('P1Y');
}

static::$personalAccessTokensExpireIn = Carbon::now()->diff($date);
static::$personalAccessTokensExpireIn = $date instanceof DateTimeInterface
? Carbon::now()->diff($date)
: $date;

return new static;
}
Expand Down

0 comments on commit 21099f1

Please sign in to comment.