mirror of https://github.com/golang-jwt/jwt.git
Merge pull request #183 from hnakamur/support_rs256_in_jwt_command
Support RS256 algorithm in jwt command
This commit is contained in:
commit
2268707a8f
|
@ -6,8 +6,8 @@ the command line.
|
||||||
|
|
||||||
The following will create and sign a token, then verify it and output the original claims:
|
The following will create and sign a token, then verify it and output the original claims:
|
||||||
|
|
||||||
echo {\"foo\":\"bar\"} | bin/jwt -key test/sample_key -alg RS256 -sign - | bin/jwt -key test/sample_key.pub -verify -
|
echo {\"foo\":\"bar\"} | ./jwt -key ../../test/sample_key -alg RS256 -sign - | ./jwt -key ../../test/sample_key.pub -alg RS256 -verify -
|
||||||
|
|
||||||
To simply display a token, use:
|
To simply display a token, use:
|
||||||
|
|
||||||
echo $JWT | jwt -show -
|
echo $JWT | ./jwt -show -
|
||||||
|
|
|
@ -134,6 +134,8 @@ func verifyToken() error {
|
||||||
}
|
}
|
||||||
if isEs() {
|
if isEs() {
|
||||||
return jwt.ParseECPublicKeyFromPEM(data)
|
return jwt.ParseECPublicKeyFromPEM(data)
|
||||||
|
} else if isRs() {
|
||||||
|
return jwt.ParseRSAPublicKeyFromPEM(data)
|
||||||
}
|
}
|
||||||
return data, nil
|
return data, nil
|
||||||
})
|
})
|
||||||
|
@ -218,6 +220,15 @@ func signToken() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if isRs() {
|
||||||
|
if k, ok := key.([]byte); !ok {
|
||||||
|
return fmt.Errorf("Couldn't convert key data to key")
|
||||||
|
} else {
|
||||||
|
key, err = jwt.ParseRSAPrivateKeyFromPEM(k)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if out, err := token.SignedString(key); err == nil {
|
if out, err := token.SignedString(key); err == nil {
|
||||||
|
@ -265,3 +276,7 @@ func showToken() error {
|
||||||
func isEs() bool {
|
func isEs() bool {
|
||||||
return strings.HasPrefix(*flagAlg, "ES")
|
return strings.HasPrefix(*flagAlg, "ES")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isRs() bool {
|
||||||
|
return strings.HasPrefix(*flagAlg, "RS")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue