-
Notifications
You must be signed in to change notification settings - Fork 0
Add JwtInfo command #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
41ad797
feat: add jwtinfo command
xenOs76 dc24db7
chore: deps update
xenOs76 a4d0cf9
ci: add devenv tests for jwtinfo
xenOs76 4d63db4
ci: jwtinfo test creds via env
xenOs76 52ca5d8
ci: comment out file checks in devenv shell
xenOs76 bdff950
ci: add git-hook input to devenv
xenOs76 bd62c08
ci: codeChecks workflow continue on test coverage fail
xenOs76 811914b
ci: comment jwtinfo tests in devenv
xenOs76 111761e
fix: base64 decoding, linting
xenOs76 841ed64
ci: report fails from test coverage on main only
xenOs76 5a56ffa
fix: check type when extracting time claims
xenOs76 bcd3f65
ci: refine file input checks and webserver reponses
xenOs76 1c59677
fix: remove unused struct
xenOs76 d2c3c6b
ci: devenv test
xenOs76 b9fbf2f
test: ci pipeline break
xenOs76 075fba9
test: split devenv shell commands
xenOs76 72e4ef0
test: remove pipeline break
xenOs76 784ade4
test: run build in a separate ci step
xenOs76 48a947f
test: install-nix-action use nixpkgs stable
xenOs76 414cee3
test: add stable nixpath to devenv install step in ci
xenOs76 46ce155
ci: disble devenv related tests for Github actions
xenOs76 14a1662
ci: add tests for DecodeBase64, PrintTokenInfo and unmarshallTokenTim…
xenOs76 56b762f
Merge branch 'main' into feat/add_jwtinfo
xenOs76 efc39b2
refactor: check on token elements lenght and context in ParseTokenData
xenOs76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| Copyright © 2026 Zeno Belli <xeno@os76.xyz> | ||
| */ | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| "github.com/MicahParks/keyfunc/v3" | ||
| "github.com/spf13/cobra" | ||
| "github.com/xenos76/https-wrench/internal/jwtinfo" | ||
| ) | ||
|
|
||
| var ( | ||
| flagNameRequestJSONValues = "request-values-json" | ||
| flagNameRequestURL = "request-url" | ||
| flagNameJwksURL = "validation-url" | ||
| requestJSONValues string | ||
| requestURL string | ||
| jwksURL string | ||
| keyfuncDefOverride keyfunc.Override | ||
| ) | ||
|
|
||
| var jwtinfoCmd = &cobra.Command{ | ||
| Use: "jwtinfo", | ||
| Short: "Request and display JWT token data", | ||
| Long: `Request and display JWT token data.`, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| var err error | ||
| client := &http.Client{} | ||
| requestValuesMap := make(map[string]string) | ||
|
|
||
| if requestJSONValues != "" { | ||
| requestValuesMap, err = jwtinfo.ParseRequestJSONValues( | ||
| requestJSONValues, | ||
| requestValuesMap, | ||
| ) | ||
| if err != nil { | ||
| fmt.Printf( | ||
| "error while parsing request's values JSON string: %s", | ||
| err, | ||
| ) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| tokenData, err := jwtinfo.RequestToken( | ||
| requestURL, | ||
| requestValuesMap, | ||
| client, | ||
| io.ReadAll, | ||
| ) | ||
| if err != nil { | ||
| fmt.Printf("error while requesting token data: %s\n", err) | ||
| return | ||
| } | ||
|
|
||
| err = tokenData.DecodeBase64() | ||
| if err != nil { | ||
| fmt.Printf("DecodeBase64 error: %s\n", err) | ||
| return | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // TODO: turn into method | ||
| token, err := jwtinfo.ParseTokenData(tokenData, jwksURL, keyfuncDefOverride) | ||
| if err != nil { | ||
| fmt.Printf("error while parsing token data: %s\n", err) | ||
| return | ||
| } | ||
|
|
||
| fmt.Printf("Token valid: %v\n", token.Valid) | ||
|
|
||
| err = jwtinfo.PrintTokenInfo(tokenData, os.Stdout) | ||
| if err != nil { | ||
| fmt.Printf("error while printing token data: %s\n", err) | ||
| return | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(jwtinfoCmd) | ||
|
|
||
| jwtinfoCmd.Flags().StringVar( | ||
| &requestURL, | ||
| flagNameRequestURL, | ||
| "", | ||
| "HTTP address to use for the JWT token request", | ||
| ) | ||
|
|
||
| jwtinfoCmd.Flags().StringVar( | ||
| &requestJSONValues, | ||
| flagNameRequestJSONValues, | ||
| "", | ||
| "JSON encoded values to use for the JWT token request", | ||
| ) | ||
|
|
||
| jwtinfoCmd.Flags().StringVar( | ||
| &jwksURL, | ||
| flagNameJwksURL, | ||
| "", | ||
| "Url of the JSON Web Key Set (JWKS) to use for validating the JWT token", | ||
| ) | ||
|
|
||
| // Cobra supports local flags which will only run when this command | ||
| // is called directly, e.g.: | ||
| // jwtinfoCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.