REQ: Helper method to provide direct access to JWT payload #1572
Replies: 6 comments
-
Are you really sure it is a good idea? As far as I know, the base64 encoded subject, that's baked into every token, should because of security implications only contain as little user information as possible. The logged in user object gets fetched using the JWT the user got from the login response. Only user.id or similar should be used as the token subject, because the client side will fetch the rest of the user object from the server and set it in the client. Meaning that your server does the important stuff, and keeping certain operations to the server where it belongs. You can obviously could do it like you described, but as far as I know, even the JWT spec. says that the base64 decoded data should not be trusted unless you also can verify data using your secret key, but that would mean you've to store secret key information within the browser, and that would be a very bad idea... |
Beta Was this translation helpful? Give feedback.
-
I have a user ID in the token, but it's a long GUID that's not related to the username. There's a single "The logged in user object gets fetched using the JWT the user got from the login response." Right - that's what I'm saying - I have to get inside the token to get the username to be able to fetch the user object from the API. My only option is to parse the token server-side which then calls the user endpoint with the correct required username - hence the required use of jwtDecode to get to the "unique_name" value it contains. |
Beta Was this translation helpful? Give feedback.
-
Hi. Sorry for short answer it's late night. But the |
Beta Was this translation helpful? Give feedback.
-
A serious security note is that you CANNOT TRUST ON JWT WITHOUT CHECKING THE SIGNATURE. |
Beta Was this translation helpful? Give feedback.
-
Generally I agree with these warnings about verifying JWTs. However, @nathanchase is referring to the client reading claims in the JWT produced by a server-side API, and:
Having said that, it's good to know that decodeJWT is on its way. |
Beta Was this translation helpful? Give feedback.
-
@pi0 Is there any update on this issue? it looks like #192 and #182 are both either closed or merged, however I don't see their changes in the current release. It looks simple enough to implement locally, but I'd prefer to use it baked into the auth-module if possible. |
Beta Was this translation helpful? Give feedback.
-
What problem does this feature solve?
Instead of making a separate call to an API endpoint for user data, it would be nice to be able to simply access the username that already exists inside the encoded JWT data object.
A simple function like the following (that takes advantage of jwtDecode) would suffice:
This will provide the JWT's data object, like:
What does the proposed changes look like?
Offer a method to access the JWT payload directly
Beta Was this translation helpful? Give feedback.
All reactions