mirror of https://github.com/golang-jwt/jwt.git
Merge pull request #46 from albrow/use-signing-methods-directly
Reference signing methods directly instead of by a string name
This commit is contained in:
commit
93e34196bb
|
@ -34,7 +34,7 @@ Parsing and verifying tokens is pretty straight forward. You pass in the token
|
|||
|
||||
```go
|
||||
// Create the token
|
||||
token := jwt.New(jwt.GetSigningMethod("HS256"))
|
||||
token := jwt.New(SigningMethodHS256)
|
||||
// Set some claims
|
||||
token.Claims["foo"] = "bar"
|
||||
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
||||
|
|
|
@ -104,7 +104,7 @@ func makeSample(c map[string]interface{}) string {
|
|||
panic(e.Error())
|
||||
}
|
||||
|
||||
token := New(GetSigningMethod("RS256"))
|
||||
token := New(SigningMethodRS256)
|
||||
token.Claims = c
|
||||
s, e := token.SignedString(key)
|
||||
|
||||
|
|
|
@ -80,14 +80,13 @@ func TestRSASign(t *testing.T) {
|
|||
|
||||
func TestRSAVerifyWithPreParsedPrivateKey(t *testing.T) {
|
||||
key, _ := ioutil.ReadFile("test/sample_key.pub")
|
||||
method := GetSigningMethod("RS256").(*SigningMethodRSA)
|
||||
parsedKey, err := ParseRSAPublicKeyFromPEM(key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testData := rsaTestData[0]
|
||||
parts := strings.Split(testData.tokenString, ".")
|
||||
err = method.Verify(strings.Join(parts[0:2], "."), parts[2], parsedKey)
|
||||
err = SigningMethodRS256.Verify(strings.Join(parts[0:2], "."), parts[2], parsedKey)
|
||||
if err != nil {
|
||||
t.Errorf("[%v] Error while verifying key: %v", testData.name, err)
|
||||
}
|
||||
|
@ -95,14 +94,13 @@ func TestRSAVerifyWithPreParsedPrivateKey(t *testing.T) {
|
|||
|
||||
func TestRSAWithPreParsedPrivateKey(t *testing.T) {
|
||||
key, _ := ioutil.ReadFile("test/sample_key")
|
||||
method := GetSigningMethod("RS256").(*SigningMethodRSA)
|
||||
parsedKey, err := ParseRSAPrivateKeyFromPEM(key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testData := rsaTestData[0]
|
||||
parts := strings.Split(testData.tokenString, ".")
|
||||
sig, err := method.Sign(strings.Join(parts[0:2], "."), parsedKey)
|
||||
sig, err := SigningMethodRS256.Sign(strings.Join(parts[0:2], "."), parsedKey)
|
||||
if err != nil {
|
||||
t.Errorf("[%v] Error signing token: %v", testData.name, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue