Skip to content

[12.x] Allow token "expires in" to be defined as date interval #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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