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

Allow for removing JWT fields via json configuration. #1227

Conversation

AndrewJDR
Copy link

@AndrewJDR AndrewJDR commented Feb 23, 2019

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.

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.* (feathersjs#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.
@daffl
Copy link
Member

daffl commented Apr 1, 2019

Thank you for the pull request @AndrewJDR. I included a change that makes this possible in the new authentication version which is currently being finalized.

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