Skip to content

Add dedicated token lifetime for client credentials grant#1880

Merged
taylorotwell merged 2 commits intolaravel:13.xfrom
sajanp:client-credentials-token-lifetime
Feb 16, 2026
Merged

Add dedicated token lifetime for client credentials grant#1880
taylorotwell merged 2 commits intolaravel:13.xfrom
sajanp:client-credentials-token-lifetime

Conversation

@sajanp
Copy link
Contributor

@sajanp sajanp commented Jan 28, 2026

Summary

This PR adds a Passport::clientCredentialsTokensExpireIn() method for configuring token lifetimes specifically for the client credentials grant, mirroring the existing personalAccessTokensExpireIn() pattern.

This is a non-breaking change. When not explicitly configured, client credentials tokens continue to use Passport::tokensExpireIn() as before.

Motivation

The client credentials grant is designed for autonomous machine-to-machine interactions where tokens are regenerated automatically. Currently there is no way to configure token lifetime specifically for this grant type without affecting all other grants.

Many developers using Laravel Passport may not be familiar with the security implications of long-lived tokens or the nuances between OAuth 2.0 grant types. Providing a dedicated configuration method helps guide them toward better security practices.

Industry Guidance

Usage

use DateInterval;
use Laravel\Passport\Passport;

public function boot(): void
{
    Passport::clientCredentialsTokensExpireIn(new DateInterval('PT1H'));
}

Changes

  • Added Passport::$clientCredentialsTokensExpireIn property and Passport::clientCredentialsTokensExpireIn() method
  • Service provider uses clientCredentialsTokensExpireIn() ?? tokensExpireIn() for backwards compatibility
  • Added test for custom client credentials token expiration

@hafezdivandari
Copy link
Contributor

hafezdivandari commented Jan 28, 2026

Related to #1847 (comment)

Being able to set a custom expiration time for client credential tokens is useful, but my suggestion is to set the default to 1 year as is, and send it against 13.x without a breaking change. Then you can send another PR/issue to request for 1 hour default in the next major version.

@sajanp
Copy link
Contributor Author

sajanp commented Jan 28, 2026

Related to #1847 (comment)

Being able to set a custom expiration time for client credential tokens is useful, but my suggestion is to set the default to 1 year as is, and send it against 13.x without a breaking change. Then you can send another PR/issue to request for 1 hour default in the next major version.

I think that is fair. I will do just that later today. Thanks.

@sajanp sajanp changed the title [14.x] Add clientCredentialsTokensExpireIn() with 1 hour default [BREAKING] [WIP] Add clientCredentialsTokensExpireIn() with 1 hour default Jan 29, 2026
@sajanp sajanp marked this pull request as draft January 29, 2026 02:22
@sajanp sajanp force-pushed the client-credentials-token-lifetime branch from 0b0b1d3 to 9637ccf Compare February 16, 2026 00:00
@sajanp sajanp changed the title [WIP] Add clientCredentialsTokensExpireIn() with 1 hour default Add dedicated token lifetime for client credentials grant Feb 16, 2026
@sajanp sajanp marked this pull request as ready for review February 16, 2026 00:05
@sajanp
Copy link
Contributor Author

sajanp commented Feb 16, 2026

Took me a while to come back to this - apologies. The PR has been fixed/updated.

@taylorotwell taylorotwell merged commit 81c3dc7 into laravel:13.x Feb 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants