mirror of https://github.com/golang-jwt/jwt.git
signingn
This commit is contained in:
parent
d736b8f860
commit
5119d0e151
36
jwt.go
36
jwt.go
|
@ -14,6 +14,7 @@ type Token struct {
|
||||||
Header map[string]interface{}
|
Header map[string]interface{}
|
||||||
Claims map[string]interface{}
|
Claims map[string]interface{}
|
||||||
Method SigningMethod
|
Method SigningMethod
|
||||||
|
// This is only populated when you Parse a token
|
||||||
Signature string
|
Signature string
|
||||||
Valid bool
|
Valid bool
|
||||||
}
|
}
|
||||||
|
@ -28,16 +29,37 @@ func New(method SigningMethod)*Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sign(key []byte) error {
|
func (t *Token) SignedString(key []byte)(string, error) {
|
||||||
return nil
|
var sig, sstr string
|
||||||
|
var err error
|
||||||
|
if sstr, err = t.SigningString(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if sig, err = t.Method.Sign(sstr, key); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.Join([]string{sstr, sig}, "."), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SigningString()string {
|
func (t *Token) SigningString()(string, error) {
|
||||||
return ""
|
var err error
|
||||||
}
|
parts := make([]string, 2)
|
||||||
|
for i, _ := range parts {
|
||||||
|
var source map[string]interface{}
|
||||||
|
if i == 0 {
|
||||||
|
source = t.Header
|
||||||
|
} else {
|
||||||
|
source = t.Claims
|
||||||
|
}
|
||||||
|
|
||||||
func String()string {
|
var jsonValue []byte
|
||||||
return ""
|
if jsonValue, err = json.Marshal(source); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
parts[i] = EncodeSegment(jsonValue)
|
||||||
|
}
|
||||||
|
return strings.Join(parts, "."), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse, validate, and return a token.
|
// Parse, validate, and return a token.
|
||||||
|
|
Loading…
Reference in New Issue