Add JWT token expiration at JWTSettings level - NominalDiffTime #1599
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
The ability to set expiration to the
JWT Token
inservant-auth-server
library, rests on theCookieSettings
data type configuration and in particular in the fieldcookieExpires
as we can appreciate it here.Discussion
The problems regarding using this field for setting
JWT Token
expiration time are the following:CookieSettings
are usually created at application startup time and it keeps with the same values during the whole application life cycle. SincecookieExpires
is an absolute and deterministic point in time, futuresJWT Tokens
will contain precisely the same expiration time leading to an undesired behavior and expiring the token upon creation.CookieSettings
is a particular Data Type for all the cookies andJWT Token
should not be coupled to the rest of the cookies.JWT Tokens
with specificDiffTime
expirations, like for example configure the authentication context to create a JWT that expires in 2 hours, even usingCookieSettings.cookieExpires
.acceptLogin
function and the creation of theCookieSettings
value every time the entity authenticates successfully, but this authentication setup is manual and cannot be done withBasicAuthentication
combinator.Proposal
The proposal is implemented in this PR and includes the following changes:
expiresIn :: Maybe NominalDiffTime
inJWTSettings
Maybe UTCTime
parameter frommakeJWT
function.makeJWT
function usinggetCurrentTime + expiresIn
if it is present.Solution
JWTSettings
andCookieSettings
but allow the user to set an optionalNominalDiffTime
to calculate the expiration of theJWT Token
upon token creation if the value is present.acceptLogin
and allowingBasicAuthentication
context to handle the creation of the token by itself.