Skip to content
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

[10.x] Define token lifetimes as DateInterval instead of DateTime #1496

Conversation

DeepDiver1975
Copy link

@DeepDiver1975 DeepDiver1975 commented Oct 26, 2021

Provides an easier use in a Laravel Octane deployment

see laravel/framework#39366

Background

Passport::tokensExpireIn, Passport::refreshTokensExpireIn and Passport::personalAccessTokensExpireIn use explicit datetimes.
These methods are usually called in AuthServiceProvider.

Problem

With octane service providers are called once on startup which means that the explicit expiry datetimes are sent on startup and never being updated. As a result the longer an octane instance runs the shorter the token lifetimes get.

@DeepDiver1975 DeepDiver1975 force-pushed the feat/specify-token-lifetimes-as-intervals branch from 47e22e7 to 908b16a Compare October 26, 2021 12:13
…ovides an easier use in a Laravel Octane deployment
@DeepDiver1975 DeepDiver1975 force-pushed the feat/specify-token-lifetimes-as-intervals branch from 908b16a to 0502520 Compare October 26, 2021 12:16
@driesvints driesvints changed the title feat: define token lifetimes as DateInterval instead of DateTime - pr… [10.x] Define token lifetimes as DateInterval instead of DateTime Oct 26, 2021
@driesvints
Copy link
Member

Hmm you're right this is indeed an issue. However, this would be a breaking change here. I think the correct course of action here is to use your suggestion from the issue to use an event handler like Socialite:

https://github.com/laravel/octane/pull/400/files#diff-713c2b10a1e78ad1a57b948bbecdeace4afcef924eef6ce3c0899d2fa2fe7134R56

So could you PR that instead to Octane?

I do think you're correct about the behavior. Adding an interval or time in seconds is probably a better way to deal with this than setting a DateTime instance.

@DeepDiver1975
Copy link
Author

DeepDiver1975 commented Oct 26, 2021

So could you PR that instead to Octane?

I was thinking about this already as well .... but what operation/logic should be executed on Passport?

That seems straight forward but will degrade the life time over time.

Passport::tokensExpireIn(Passport::tokensExpireIn());
...

I don't think this can be fixed without a change in Passport.

@driesvints
Copy link
Member

I'll need to have a look myself. Hopefully later this week.

@driesvints driesvints marked this pull request as draft October 26, 2021 18:19
@DeepDiver1975
Copy link
Author

One idea could be to compute the DateInterval upon calling tokensExpireIn($date) and store the interval instead of the expire date.

tokensExpireAt is public so we need second property ... unless this is not considered a BC break.

@driesvints
Copy link
Member

@DeepDiver1975 You were correct, it's best that we solve this in Passport. I took a different approach however, one that's not breaking. Can you review #1500 and let me know if that looks good to you?

@driesvints
Copy link
Member

Replaced by #1500. @DeepDiver1975 should be out on Tuesday somewhere.

@driesvints driesvints closed this Oct 28, 2021
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.

2 participants