Skip to content

Commit cea3686

Browse files
authored
Add JwtInfo command (#21)
* feat: add jwtinfo command Add JwtInfo command for initial testing
1 parent 5f792b4 commit cea3686

22 files changed

+2263
-132
lines changed

.github/workflows/codeChecks.yml

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,34 @@ jobs:
4646
go-package: ./...
4747
work-dir: .
4848

49-
devenv_test:
50-
needs: go_tests
51-
runs-on: ubuntu-latest
52-
53-
steps:
54-
- name: Checkout
55-
uses: actions/checkout@v5
56-
57-
- uses: cachix/install-nix-action@v31
58-
with:
59-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
60-
61-
- uses: cachix/cachix-action@v16
62-
with:
63-
name: devenv
64-
65-
- name: Install devenv.sh
66-
run: nix profile add nixpkgs#devenv
67-
68-
- name: Build the devenv shell and run tests
69-
run: devenv test
70-
timeout-minutes: 15
71-
49+
# # WARN this action will install devenv 2.x.x while
50+
# # the repo still uses 1.11.1. Disabling it until devenv is upgraded
51+
# devenv_test:
52+
# needs: go_tests
53+
# runs-on: ubuntu-latest
54+
#
55+
# steps:
56+
# - name: Checkout
57+
# uses: actions/checkout@v5
58+
#
59+
# - uses: cachix/install-nix-action@v31
60+
# with:
61+
# github_access_token: ${{ secrets.GITHUB_TOKEN }}
62+
# nix_path: nixpkgs=channel:nixos-25.11
63+
#
64+
# - uses: cachix/cachix-action@v16
65+
# with:
66+
# name: devenv
67+
#
68+
# - name: Install devenv.sh
69+
# run: nix profile add nixpkgs#devenv
70+
#
71+
# - name: Build the devenv shell and run any pre-commit hooks
72+
# env:
73+
# JWTINFO_TEST_AUTH0: ${{ secrets.JWTINFO_TEST_AUTH0 }}
74+
# run: devenv test
75+
# timeout-minutes: 15
76+
#
7277
go_test_coverage_check:
7378
needs: go_tests
7479
runs-on: ubuntu-latest
@@ -82,33 +87,34 @@ jobs:
8287
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
8388

8489
- name: check test coverage
90+
continue-on-error: ${{ github.ref_name != 'main' }}
8591
uses: vladopajic/go-test-coverage@v2
8692
with:
8793
config: ./.testcoverage.yml
8894
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
8995
git-branch: badges
9096

91-
goreleaser_test:
92-
needs: devenv_test
93-
runs-on: ubuntu-latest
94-
95-
steps:
96-
- name: Checkout
97-
uses: actions/checkout@v5
98-
with:
99-
fetch-depth: 0
100-
101-
- name: Set up QEMU
102-
uses: docker/setup-qemu-action@v3
103-
104-
- name: Set up Go
105-
uses: actions/setup-go@v6
106-
with:
107-
go-version: "1.25"
108-
109-
- name: Run GoReleaser test
110-
uses: goreleaser/goreleaser-action@v6
111-
with:
112-
version: "~> 2"
113-
args: release --snapshot --clean
114-
workdir: .
97+
# goreleaser_test:
98+
# needs: devenv_test
99+
# runs-on: ubuntu-latest
100+
#
101+
# steps:
102+
# - name: Checkout
103+
# uses: actions/checkout@v5
104+
# with:
105+
# fetch-depth: 0
106+
#
107+
# - name: Set up QEMU
108+
# uses: docker/setup-qemu-action@v3
109+
#
110+
# - name: Set up Go
111+
# uses: actions/setup-go@v6
112+
# with:
113+
# go-version: "1.25"
114+
#
115+
# - name: Run GoReleaser test
116+
# uses: goreleaser/goreleaser-action@v6
117+
# with:
118+
# version: "~> 2"
119+
# args: release --snapshot --clean
120+
# workdir: .

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ linters:
3232
enable-all-rules: true
3333
severity: warning
3434
rules:
35-
3635
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#add-constant
3736
- name: add-constant
3837
severity: warning
@@ -45,7 +44,7 @@ linters:
4544
severity: warning
4645
disabled: false
4746
exclude: [""]
48-
arguments: [100]
47+
arguments: [120]
4948

5049
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#cognitive-complexity
5150
- name: cognitive-complexity

cmd/jwtinfo.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
Copyright © 2026 Zeno Belli <xeno@os76.xyz>
3+
*/
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
"io"
10+
"net/http"
11+
"os"
12+
13+
"github.com/MicahParks/keyfunc/v3"
14+
"github.com/spf13/cobra"
15+
"github.com/xenos76/https-wrench/internal/jwtinfo"
16+
)
17+
18+
var (
19+
flagNameRequestJSONValues = "request-values-json"
20+
flagNameRequestURL = "request-url"
21+
flagNameJwksURL = "validation-url"
22+
requestJSONValues string
23+
requestURL string
24+
jwksURL string
25+
keyfuncDefOverride keyfunc.Override
26+
)
27+
28+
var jwtinfoCmd = &cobra.Command{
29+
Use: "jwtinfo",
30+
Short: "Request and display JWT token data",
31+
Long: `Request and display JWT token data.`,
32+
Run: func(cmd *cobra.Command, args []string) {
33+
var err error
34+
client := &http.Client{}
35+
requestValuesMap := make(map[string]string)
36+
37+
if requestJSONValues != "" {
38+
requestValuesMap, err = jwtinfo.ParseRequestJSONValues(
39+
requestJSONValues,
40+
requestValuesMap,
41+
)
42+
if err != nil {
43+
fmt.Printf(
44+
"error while parsing request's values JSON string: %s",
45+
err,
46+
)
47+
return
48+
}
49+
}
50+
51+
tokenData, err := jwtinfo.RequestToken(
52+
requestURL,
53+
requestValuesMap,
54+
client,
55+
io.ReadAll,
56+
)
57+
if err != nil {
58+
fmt.Printf("error while requesting token data: %s\n", err)
59+
return
60+
}
61+
62+
err = tokenData.DecodeBase64()
63+
if err != nil {
64+
fmt.Printf("DecodeBase64 error: %s\n", err)
65+
return
66+
}
67+
68+
// TODO: turn into method
69+
token, err := jwtinfo.ParseTokenData(tokenData, jwksURL, keyfuncDefOverride)
70+
if err != nil {
71+
fmt.Printf("error while parsing token data: %s\n", err)
72+
return
73+
}
74+
75+
fmt.Printf("Token valid: %v\n", token.Valid)
76+
77+
err = jwtinfo.PrintTokenInfo(tokenData, os.Stdout)
78+
if err != nil {
79+
fmt.Printf("error while printing token data: %s\n", err)
80+
return
81+
}
82+
},
83+
}
84+
85+
func init() {
86+
rootCmd.AddCommand(jwtinfoCmd)
87+
88+
jwtinfoCmd.Flags().StringVar(
89+
&requestURL,
90+
flagNameRequestURL,
91+
"",
92+
"HTTP address to use for the JWT token request",
93+
)
94+
95+
jwtinfoCmd.Flags().StringVar(
96+
&requestJSONValues,
97+
flagNameRequestJSONValues,
98+
"",
99+
"JSON encoded values to use for the JWT token request",
100+
)
101+
102+
jwtinfoCmd.Flags().StringVar(
103+
&jwksURL,
104+
flagNameJwksURL,
105+
"",
106+
"Url of the JSON Web Key Set (JWKS) to use for validating the JWT token",
107+
)
108+
109+
// Cobra supports local flags which will only run when this command
110+
// is called directly, e.g.:
111+
// jwtinfoCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
112+
}

devenv.lock

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1766843567,
6+
"lastModified": 1772483048,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "d0f2c8545f09e5aba9d321079a284b550371879d",
9+
"rev": "40f410e3a5e0f9198cf67bfa8673c9a17d8c605c",
1010
"type": "github"
1111
},
1212
"original": {
@@ -19,14 +19,14 @@
1919
"flake-compat": {
2020
"flake": false,
2121
"locked": {
22-
"lastModified": 1766661267,
23-
"owner": "edolstra",
22+
"lastModified": 1767039857,
23+
"owner": "NixOS",
2424
"repo": "flake-compat",
25-
"rev": "f275e157c50c3a9a682b4c9b4aa4db7a4cd3b5f2",
25+
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
2626
"type": "github"
2727
},
2828
"original": {
29-
"owner": "edolstra",
29+
"owner": "NixOS",
3030
"repo": "flake-compat",
3131
"type": "github"
3232
}
@@ -35,15 +35,13 @@
3535
"inputs": {
3636
"flake-compat": "flake-compat",
3737
"gitignore": "gitignore",
38-
"nixpkgs": [
39-
"nixpkgs"
40-
]
38+
"nixpkgs": "nixpkgs"
4139
},
4240
"locked": {
43-
"lastModified": 1765911976,
41+
"lastModified": 1772024342,
4442
"owner": "cachix",
4543
"repo": "git-hooks.nix",
46-
"rev": "b68b780b69702a090c8bb1b973bab13756cc7a27",
44+
"rev": "6e34e97ed9788b17796ee43ccdbaf871a5c2b476",
4745
"type": "github"
4846
},
4947
"original": {
@@ -74,25 +72,42 @@
7472
},
7573
"nixpkgs": {
7674
"locked": {
77-
"lastModified": 1764580874,
78-
"owner": "cachix",
79-
"repo": "devenv-nixpkgs",
80-
"rev": "dcf61356c3ab25f1362b4a4428a6d871e84f1d1d",
75+
"lastModified": 1773597492,
76+
"owner": "NixOS",
77+
"repo": "nixpkgs",
78+
"rev": "a07d4ce6bee67d7c838a8a5796e75dff9caa21ef",
8179
"type": "github"
8280
},
8381
"original": {
84-
"owner": "cachix",
85-
"ref": "rolling",
86-
"repo": "devenv-nixpkgs",
82+
"owner": "NixOS",
83+
"ref": "nixpkgs-unstable",
84+
"repo": "nixpkgs",
85+
"type": "github"
86+
}
87+
},
88+
"nixpkgs-src": {
89+
"flake": false,
90+
"locked": {
91+
"lastModified": 1769922788,
92+
"narHash": "sha256-H3AfG4ObMDTkTJYkd8cz1/RbY9LatN5Mk4UF48VuSXc=",
93+
"owner": "NixOS",
94+
"repo": "nixpkgs",
95+
"rev": "207d15f1a6603226e1e223dc79ac29c7846da32e",
96+
"type": "github"
97+
},
98+
"original": {
99+
"owner": "NixOS",
100+
"ref": "nixpkgs-unstable",
101+
"repo": "nixpkgs",
87102
"type": "github"
88103
}
89104
},
90105
"nixpkgs-stable": {
91106
"locked": {
92-
"lastModified": 1766736597,
107+
"lastModified": 1772047000,
93108
"owner": "NixOS",
94109
"repo": "nixpkgs",
95-
"rev": "f560ccec6b1116b22e6ed15f4c510997d99d5852",
110+
"rev": "1267bb4920d0fc06ea916734c11b0bf004bbe17e",
96111
"type": "github"
97112
},
98113
"original": {
@@ -102,11 +117,29 @@
102117
"type": "github"
103118
}
104119
},
120+
"nixpkgs_2": {
121+
"inputs": {
122+
"nixpkgs-src": "nixpkgs-src"
123+
},
124+
"locked": {
125+
"lastModified": 1770434727,
126+
"owner": "cachix",
127+
"repo": "devenv-nixpkgs",
128+
"rev": "8430f16a39c27bdeef236f1eeb56f0b51b33d348",
129+
"type": "github"
130+
},
131+
"original": {
132+
"owner": "cachix",
133+
"ref": "rolling",
134+
"repo": "devenv-nixpkgs",
135+
"type": "github"
136+
}
137+
},
105138
"root": {
106139
"inputs": {
107140
"devenv": "devenv",
108141
"git-hooks": "git-hooks",
109-
"nixpkgs": "nixpkgs",
142+
"nixpkgs": "nixpkgs_2",
110143
"nixpkgs-stable": "nixpkgs-stable",
111144
"pre-commit-hooks": [
112145
"git-hooks"

0 commit comments

Comments
 (0)