Skip to content
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

Allow none algorithm in jwt command #121

Merged
merged 1 commit into from Nov 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions cmd/jwt/main.go
Expand Up @@ -128,6 +128,9 @@ func verifyToken() error {

// Parse the token. Load the key from command line option
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (interface{}, error) {
if isNone() {
return jwt.UnsafeAllowNoneSignatureType, nil
}
data, err := loadData(*flagKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -192,9 +195,13 @@ func signToken() error {

// get the key
var key interface{}
key, err = loadData(*flagKey)
if err != nil {
return fmt.Errorf("couldn't read key: %w", err)
if isNone() {
key = jwt.UnsafeAllowNoneSignatureType
} else {
key, err = loadData(*flagKey)
if err != nil {
return fmt.Errorf("couldn't read key: %w", err)
}
}

// get the signing alg
Expand Down Expand Up @@ -296,6 +303,10 @@ func isEd() bool {
return *flagAlg == "EdDSA"
}

func isNone() bool {
return *flagAlg == "none"
}

type ArgList map[string]string

func (l ArgList) String() string {
Expand Down