Repository navigation
(#1061) Add jwt command to decode the user JWT in a creds file - #1750
Conversation
ripienaar
left a comment
There was a problem hiding this comment.
Thanks for this contribution, generally please review the prevailing style of the project and make sure your code looks like it belongs in the project.
Other than that I'd say there's some extra code here that isn't probably already available in the jwt package
| return base64.RawURLEncoding.DecodeString(s) | ||
| } | ||
|
|
||
| func (c *decodeJwtCmd) DecodeCreds(jwtStr string) error { |
There was a problem hiding this comment.
I bet there are already helpers for this in the jwt library, ParseDecoratedJWT() maybe?
There was a problem hiding this comment.
thank you for the reviews, i am working on them, i had a question there is another helper DecodeGeneric that exctracts just the claims, should i just go ahread and use it and skip adding decoded headers to output? or should i keep the decoded headers, i am asking from a ux point of view do users need to see the decoded headers ?
There was a problem hiding this comment.
in my mind this feature should be built like this:
- you find out the type of the JWT (user, account, operator etc)
- you render each with a user friendly column interface compatible with the overall CLI design
- you have a --json flag as optional for those who want it
dumping jwt to json is not the UI, its why this has sat unimplemented so long because I just dont think this is a UX I want here, so I am not inclined to say we should not accept it as designed here
There was a problem hiding this comment.
i understand the direction now , i apologise if this is a newbie question but , currently i get the user jwt from a .creds file , the operator and account info is usually present in the server.conf in the server , so do i need to fetch it or can i simply allow the users to give me a .jwt file path ?
There was a problem hiding this comment.
the original issue mentions various places to get JWT from - creds file yes that would be a user, but also a arbitrary JWT and we have quite a few types of JWT from different places including just a .jwt file
|
@ripienaar i have rewritten the whole thing, keeping in mind all the reviews that you gave, this is how the command output looks like :
|
|
Thank you @SagarSingh2003 this looks pretty good, we'll do a small fixup PR after appreciate your contribution! |
|
Thanks @SagarSingh2003, I've pushed a small commit to fix a linter issue. If you wouldn't mind signing your commits we can go ahead and merge this PR. |
Signed-off-by: Pieter Loubser <ploubser@gmail.com>
Signed-off-by: Pieter Loubser <ploubser@gmail.com>
4e55f9b to
9f1a306
Compare
|
Thank you @ripienaar and @ploubser for the review, @ploubser i rebased the commits and signed all of them , just a heads up that i ended up signing your commits as well so the hash has changed. . If you have the branch checked out locally, git fetch && git reset --hard origin/feat/jwt-decoder will sync you up. |
|
Thanks again @SagarSingh2003. Sorry it took me so long to merge, I was out for a few days. Appreciate the contribution :) |
|
@ploubser i went through the cleanup pr , that was a lot of work sorry for that, will do better next time. you are awesome |
|
@SagarSingh2003 no problem at all, your changes gave me a good opportunity to extract some shared code :) It looks like a lot more work than it really was! |

This PR references issue #1061
What it covers :
Not included, to keep this PR small: raw JWT string / JWT-file input,
human-friendly timestamp annotations, signature verification, jq-style
field walking, colors.
Question: should
--jsonprint only the token's exact claims? Right nowit's a combined object (header, claims, issuedAt), and decoding through
GenericClaims may drop fields it doesn't model. Happy to change it.
Note : it does not verify the signatures and is not a proof that the jwt is valid