-
Notifications
You must be signed in to change notification settings - Fork 128
misc: Renew token only when expired #3913
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
Conversation
TL;DR; Let's have an example scenario Consider: Execution:
If we want to renew the token correctly, we have decode with the attribute
This will renew the token 30 min before it expires. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lago-api/app/controllers/concerns/authenticable_user.rb
Lines 36 to 40 in 4d935ce
def decode_options | |
{ | |
algorithm: "HS256" | |
} | |
end |
This will make the token get renewed before expired and actually renew the token.
def decode_options
{
algorithm: "HS256",
exp_leeway: 30.minutes.to_i
}
end
@mariohd It works, because But yeah, not really fan of this. |
Oh you right! But in that case, we are always decoding with About exp_leeway, it's an extra time we allow. For example, token expires in 2h24m and we have a leeway of 36min. We will consider the token valid for 3h. If the token was expired more than 3h, it would raise the exception and logout the user. The goal is renew the token after it passed those 2h24 min. I would suggest that we decode the token with true and leeway and then check if the exp is bigger than the current time. If it is, token is still valid with exp only. |
## Description We currently renew the authorisation token for each request made by users. This is pointless in most cases because the token expires after 3 hours (2h24 to be exact). The aim of this PR is to renew the token only when it expires.
Description
We currently renew the authorisation token for each request made by users.
This is pointless in most cases because the token expires after 3 hours (2h24 to be exact).
The aim of this PR is to renew the token only when it expires.