Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code comments, including security consideration #107

Merged
merged 6 commits into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions parser.go
Expand Up @@ -13,9 +13,9 @@ type Parser struct {
SkipClaimsValidation bool // Skip claims validation during token parsing
}

// Parse parses, validates, and returns a token.
// Parse parses, validates, verifies the signature and returns the parsed token.
// keyFunc will receive the parsed token and should return the key for validating.
// If everything is kosher, err will be nil
// If everything is kosher, err will be nil.
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc)
}
Expand Down
14 changes: 9 additions & 5 deletions token.go
Expand Up @@ -29,11 +29,12 @@ type Token struct {
Valid bool // Is the token valid? Populated when you Parse/Verify a token
}

// New creates a new Token. Takes a signing method
// New creates a new Token with the specified a signing method and an empty map of claims.
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
func New(method SigningMethod) *Token {
return NewWithClaims(method, MapClaims{})
}

// NewWithClaims creates a new Token with the specified signing method and claims.
func NewWithClaims(method SigningMethod, claims Claims) *Token {
return &Token{
Header: map[string]interface{}{
Expand All @@ -45,7 +46,8 @@ func NewWithClaims(method SigningMethod, claims Claims) *Token {
}
}

// SignedString retrieves the complete, signed token
// SignedString creates and returns a complete, signed JWT token.
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
// The token is signed using the SigningMethod specified in the token.
func (t *Token) SignedString(key interface{}) (string, error) {
var sig, sstr string
var err error
Expand Down Expand Up @@ -82,9 +84,11 @@ func (t *Token) SigningString() (string, error) {
return strings.Join(parts, "."), nil
}

// Parse parses, validates, and returns a token.
// keyFunc will receive the parsed token and should return the key for validating.
// If everything is kosher, err will be nil
// Parse parses, validates, verifies the signature and returns the parsed token.
// keyFunc will receive the parsed token and should return the cryptographic key
// for verifying the signature.
// keyFunc should validate the 'alg' claim in the token matches the expected algorithm.
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
// If everything is kosher, err will be nil.
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
return new(Parser).Parse(tokenString, keyFunc)
}
Expand Down