This commit is contained in:
Dave Grijalva 2012-07-06 16:07:55 -07:00
parent d736b8f860
commit 5119d0e151
1 changed files with 30 additions and 8 deletions

34
jwt.go
View File

@ -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.