mirror of https://github.com/golang-jwt/jwt.git
it works
This commit is contained in:
parent
e49f2f5a18
commit
97424f0088
2
jwt.go
2
jwt.go
|
@ -63,7 +63,7 @@ func Parse(tokenString string, keyFunc func(*Token)([]byte, error)) (token *Toke
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform validation
|
// Perform validation
|
||||||
if err = token.Method.Verify(strings.Join(parts[0:1], "."), parts[2], key); err == nil {
|
if err = token.Method.Verify(strings.Join(parts[0:2], "."), parts[2], key); err == nil {
|
||||||
token.Valid = true
|
token.Valid = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
rs256.go
4
rs256.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
_ "crypto/sha256"
|
"crypto/sha256"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SigningMethodRS256 struct {}
|
type SigningMethodRS256 struct {}
|
||||||
|
@ -35,7 +35,7 @@ func (m *SigningMethodRS256) Verify(signingString, signature string, key []byte)
|
||||||
var parsedKey interface{}
|
var parsedKey interface{}
|
||||||
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err == nil {
|
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err == nil {
|
||||||
if rsaKey, ok := parsedKey.(*rsa.PublicKey); ok {
|
if rsaKey, ok := parsedKey.(*rsa.PublicKey); ok {
|
||||||
hasher := crypto.SHA256.New()
|
hasher := sha256.New()
|
||||||
hasher.Write([]byte(signingString))
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
err = rsa.VerifyPKCS1v15(rsaKey, crypto.SHA256, hasher.Sum(nil), sig)
|
err = rsa.VerifyPKCS1v15(rsaKey, crypto.SHA256, hasher.Sum(nil), sig)
|
||||||
|
|
|
@ -39,7 +39,7 @@ func TestRS256Verify(t *testing.T) {
|
||||||
parts := strings.Split(data.tokenString, ".")
|
parts := strings.Split(data.tokenString, ".")
|
||||||
|
|
||||||
method, _ := GetSigningMethod("RS256")
|
method, _ := GetSigningMethod("RS256")
|
||||||
err := method.Verify(strings.Join(parts[0:1], "."), parts[2], key)
|
err := method.Verify(strings.Join(parts[0:2], "."), parts[2], key)
|
||||||
if data.valid && err != nil {
|
if data.valid && err != nil {
|
||||||
t.Errorf("[%v] Error while verifying key: %v", data.name, err)
|
t.Errorf("[%v] Error while verifying key: %v", data.name, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue