Allow for removing JWT fields via json configuration. #1227
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.
jsonwebtoken actually supports not setting the following fields:
expiresIn
issuer
subject
audience
iat
And perhaps others.
Taking expiresIn as an example, if this is undefined, it means the JWT should never expire and will not have an exp field:
Furthermore, the option must be completely undefined to achieve this behavior, explicitly setting it to undefined, null, or 0 is not sufficient:
auth0/node-jsonwebtoken#417
This means there needs to be a way of explicitly removing these keys from the jwt options object.
feathers/authentication is always providing default values for these fields,
and didn't seem to any working facility for overwriting them programatically at runtime.
A previously mentioned technique of overriding jwt parameters via context.params.jwt.* (#776)
no longer works because context.params.jwt is not available in the auth/before hook. I don't know why this is the case, and I would have to investigate the git history extensively to find out.
In any case, I thought it would be nice to have a declarative way (rather than programmatic) to remove various jwt options/fields by setting a configuration option, so this commit adds a "jwtRemoveOptions" to the authentication section of the feathers configuration. This should be set to an array of key names to remove from the jwt options.
In addition, a conditional was placed around the setTimeout: if expiresIn is undefined it doesn't set the timeout.