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

How to handle forced re-authentication after a given time ? #1637

Closed
franck-grenier opened this issue Feb 17, 2023 · 4 comments
Closed

How to handle forced re-authentication after a given time ? #1637

franck-grenier opened this issue Feb 17, 2023 · 4 comments

Comments

@franck-grenier
Copy link

franck-grenier commented Feb 17, 2023

Hello,
I'm very happy that you implemented a force re-authentication feature with the prompt=login param in release 11.x: #1577

But I still miss something: the re-authentication should be "time related" in order to have a forced re-authentication last for a given time.

OpenID has a spec for that with prompt=login + max_age param (see https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest)

I know Passport does not implement OpenID but it looks like you started to dive into it with the prompt=login param...

I also advice you to have a look at how Auth0 handles "re-authentication": https://auth0.com/docs/authenticate/login/max-age-reauthentication. This could be done with a new claim auth_time inside the tokens. I don't know if it's possible to customize tokens provided by Passport.

Globally, my question is: with Passport, how can I force user to re-authenticate if authentication is older than a given time ?

Thanks for your help

@driesvints
Copy link
Member

@hafezdivandari can you answer this?

@franck-grenier franck-grenier changed the title How to handle forced re-authentication ? How to handle forced re-authentication after a given time ? Feb 17, 2023
@hafezdivandari
Copy link
Contributor

hafezdivandari commented Feb 18, 2023

This could be done with a new claim auth_time inside the tokens. I don't know if it's possible to customize tokens provided by Passport.

AFAIK adding custom claims to JWT tokens are not supported right now. Here is the related issue: #94, and this is the related PR on oauth2-server repo: thephpleague/oauth2-server#1122

@driesvints what you think about adding Passport::useAccessTokenEntity() to override \Laravel\Passport\Bridge\AccessToken class? Then the user will be able to override convertToJWT method and add their own custom claims.

@franck-grenier
Copy link
Author

It seems that I can achieve something with the help of this extension https://github.com/corbosman/laravel-passport-claims to add custom claims to Passport tokens.

I will be able to compare the auth_time token claim with a database stored last login time to evaluate freshness of auth.

It would be great if Passport had such a built-in feature.

@driesvints
Copy link
Member

Okay, since you found a workaround I'm going to close this. Let's see how the PR goes as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants