@@ -29,11 +29,12 @@ type Token struct {
29
29
Valid bool // Is the token valid? Populated when you Parse/Verify a token
30
30
}
31
31
32
- // New creates a new Token. Takes a signing method
32
+ // New creates a new Token with the specified signing method and an empty map of claims.
33
33
func New (method SigningMethod ) * Token {
34
34
return NewWithClaims (method , MapClaims {})
35
35
}
36
36
37
+ // NewWithClaims creates a new Token with the specified signing method and claims.
37
38
func NewWithClaims (method SigningMethod , claims Claims ) * Token {
38
39
return & Token {
39
40
Header : map [string ]interface {}{
@@ -45,7 +46,8 @@ func NewWithClaims(method SigningMethod, claims Claims) *Token {
45
46
}
46
47
}
47
48
48
- // SignedString retrieves the complete, signed token
49
+ // SignedString creates and returns a complete, signed JWT.
50
+ // The token is signed using the SigningMethod specified in the token.
49
51
func (t * Token ) SignedString (key interface {}) (string , error ) {
50
52
var sig , sstr string
51
53
var err error
@@ -82,9 +84,13 @@ func (t *Token) SigningString() (string, error) {
82
84
return strings .Join (parts , "." ), nil
83
85
}
84
86
85
- // Parse parses, validates, and returns a token.
86
- // keyFunc will receive the parsed token and should return the key for validating.
87
- // If everything is kosher, err will be nil
87
+ // Parse parses, validates, verifies the signature and returns the parsed token.
88
+ // keyFunc will receive the parsed token and should return the cryptographic key
89
+ // for verifying the signature.
90
+ // The caller is strongly encouraged to set the WithValidMethods option to
91
+ // validate the 'alg' claim in the token matches the expected algorithm.
92
+ // For more details about the importance of validating the 'alg' claim,
93
+ // see https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
88
94
func Parse (tokenString string , keyFunc Keyfunc , options ... ParserOption ) (* Token , error ) {
89
95
return NewParser (options ... ).Parse (tokenString , keyFunc )
90
96
}
0 commit comments