added claims type
This commit is contained in:
parent
8e361f3156
commit
6e61945c2c
3 changed files with 64 additions and 8 deletions
16
jwt.go
16
jwt.go
|
|
@ -323,7 +323,7 @@ type Token struct {
|
|||
signature string
|
||||
rawSignature []byte
|
||||
header map[string]interface{}
|
||||
Claims map[string]interface{}
|
||||
Claims Claims
|
||||
}
|
||||
|
||||
// String returns the tokens encoded string
|
||||
|
|
@ -352,14 +352,18 @@ func (t *Token) Data() string {
|
|||
}
|
||||
|
||||
// NewToken returns a new *Token using the provided hash algorithm and claims
|
||||
// If h is nil HS256 will be used
|
||||
func NewToken(claims map[string]interface{}, h Hash) *Token {
|
||||
if h == nil {
|
||||
h = NewHS256()
|
||||
// If claims is nil, an empty map is used
|
||||
// If hash is nil, HS256 is used
|
||||
func NewToken(claims Claims, hash Hash) *Token {
|
||||
if claims == nil {
|
||||
claims = make(Claims)
|
||||
}
|
||||
if hash == nil {
|
||||
hash = NewHS256()
|
||||
}
|
||||
return &Token{
|
||||
header: map[string]interface{}{
|
||||
"alg": h.Alg(),
|
||||
"alg": hash.Alg(),
|
||||
"typ": typ,
|
||||
},
|
||||
Claims: claims,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue