forked from mirror/jwt
fixed whitespace issue when reading tokens from stdin
This commit is contained in:
parent
8724cca5ea
commit
6b310a4cc2
|
@ -13,6 +13,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
)
|
)
|
||||||
|
@ -90,6 +91,12 @@ func verifyToken() error {
|
||||||
return fmt.Errorf("Couldn't read token: %v", err)
|
return fmt.Errorf("Couldn't read token: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trim possible whitespace from token
|
||||||
|
tokData = regexp.MustCompile(`\s*$`).ReplaceAll(tokData, []byte{})
|
||||||
|
if *flagDebug {
|
||||||
|
fmt.Fprintf(os.Stderr, "Token len: %v bytes\n", len(tokData))
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the token. Load the key from command line option
|
// Parse the token. Load the key from command line option
|
||||||
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) ([]byte, error) {
|
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) ([]byte, error) {
|
||||||
return loadData(*flagKey)
|
return loadData(*flagKey)
|
||||||
|
@ -97,8 +104,8 @@ func verifyToken() error {
|
||||||
|
|
||||||
// Print some debug data
|
// Print some debug data
|
||||||
if *flagDebug && token != nil {
|
if *flagDebug && token != nil {
|
||||||
fmt.Printf("Header:\n%v\n", token.Header)
|
fmt.Fprintf(os.Stderr, "Header:\n%v\n", token.Header)
|
||||||
fmt.Printf("Claims:\n%v\n", token.Claims)
|
fmt.Fprintf(os.Stderr, "Claims:\n%v\n", token.Claims)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print an error if we can't parse for some reason
|
// Print an error if we can't parse for some reason
|
||||||
|
@ -129,6 +136,8 @@ func signToken() error {
|
||||||
tokData, err := loadData(*flagSign)
|
tokData, err := loadData(*flagSign)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Couldn't read token: %v", err)
|
return fmt.Errorf("Couldn't read token: %v", err)
|
||||||
|
} else if *flagDebug {
|
||||||
|
fmt.Println("Token: %v bytes", len(tokData))
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the JSON of the claims
|
// parse the JSON of the claims
|
||||||
|
|
Loading…
Reference in New Issue