-
Notifications
You must be signed in to change notification settings - Fork 117
Customize the JWT payload #78
Comments
@enten I'm definitely open to it. We actually started down the route of just encoding the whole user in the JWT payload but we found that the JWT could get massive if you aren't selecting specific fields. I think your solution is great so if you want to put together a PR that would be awesome! Things to do:
We'll need to make sure it has a test. I'll be backfilling other tests today so I could help with that. |
I'm glad you like the idea.
After another code review, I prefer another solution due to the file organization: I don't want to create more file dependency for only one function (and I don't know where creates this new dependency). I suggest to update the token.create method to And we create the payload in token.create before signing it. What do you think about this modification?
What do you mean by "potential options"?
The I suggest
I'll be happy if I do not break the existing tests. I will need your help for that. |
Closed in v0.6.0 by #109. In order to customize the JWT payload you can do this: app.configure(authentication({
token: {
payload: ['email', 'name'],
}
})); |
@ekryski Is there a solution in version
|
@marshallswain How can add some payloads which come from the query result. Just like
|
Got it add before hooks before: {
create: [
auth.hooks.authenticate(['local']),
(context) => {
const { params, params: { user = {} } } = context;
params.payload = {
id: user['_id'],
username: user.username,
org: user.org,
roles: user.roles
};
}
]
} |
@CrisLi I've done a similar thing in your example, but that's causing my JWT to have the incorrect signature for some reason. Not sure what I'm doing wrong. |
Is it possible to customize the JWT payload?
After code review, I thinks that the answer is no. But I want to be sure.
What do you think about a new configuration option named
userPayload
which may be used to customize the JWT payload?userPayload
can be an array which contains extra field names to put in payload (next toidField
).To implement that feature, we should factorize the code below (existing into services/local/index.js and services/oauth/index.js) into a new
createPayload
function which acceptuser
,idField
andextraFields
(corresponding to newuserPayload
).Implementation example of
createPayload
:Do you find that feature useful?
The main purpose is to have user data without requesting the database (doesn't need to call populateUser hook for few user data).
The text was updated successfully, but these errors were encountered: