Skip to content

Commit 1275a5b

Browse files
Allow none algorithm in jwt command (#121)
1 parent f4865cd commit 1275a5b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cmd/jwt/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ func verifyToken() error {
128128

129129
// Parse the token. Load the key from command line option
130130
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (interface{}, error) {
131+
if isNone() {
132+
return jwt.UnsafeAllowNoneSignatureType, nil
133+
}
131134
data, err := loadData(*flagKey)
132135
if err != nil {
133136
return nil, err
@@ -192,9 +195,13 @@ func signToken() error {
192195

193196
// get the key
194197
var key interface{}
195-
key, err = loadData(*flagKey)
196-
if err != nil {
197-
return fmt.Errorf("couldn't read key: %w", err)
198+
if isNone() {
199+
key = jwt.UnsafeAllowNoneSignatureType
200+
} else {
201+
key, err = loadData(*flagKey)
202+
if err != nil {
203+
return fmt.Errorf("couldn't read key: %w", err)
204+
}
198205
}
199206

200207
// get the signing alg
@@ -296,6 +303,10 @@ func isEd() bool {
296303
return *flagAlg == "EdDSA"
297304
}
298305

306+
func isNone() bool {
307+
return *flagAlg == "none"
308+
}
309+
299310
type ArgList map[string]string
300311

301312
func (l ArgList) String() string {

0 commit comments

Comments
 (0)