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 ErrInvalidKeyType error messages #361

Merged
merged 6 commits into from
Nov 17, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrInvalidKeyType = errors.New("key is of invalid go type (should be []byte())")
oxisto marked this conversation as resolved.
Show resolved Hide resolved
ErrHashUnavailable = errors.New("the requested hash function is unavailable")
ErrTokenMalformed = errors.New("token is malformed")
ErrTokenUnverifiable = errors.New("token is unverifiable")
Expand Down
4 changes: 4 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func ExampleParseWithClaims_customClaimsType() {
}

token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
// []byte("AllYourBase") refers to the signing key that is used to sign the claim with
return []byte("AllYourBase"), nil
})
if err != nil {
Expand All @@ -109,6 +110,7 @@ func ExampleParseWithClaims_validationOptions() {
}

token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
// []byte("AllYourBase") refers to the signing key that is used to sign the claim with
oxisto marked this conversation as resolved.
Show resolved Hide resolved
return []byte("AllYourBase"), nil
}, jwt.WithLeeway(5*time.Second))
if err != nil {
Expand Down Expand Up @@ -148,6 +150,7 @@ func ExampleParseWithClaims_customValidation() {
tokenString := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpc3MiOiJ0ZXN0IiwiYXVkIjoic2luZ2xlIn0.QAWg1vGvnqRuCFTMcPkjZljXHh8U3L_qUjszOtQbeaA"

token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
// []byte("AllYourBase") refers to the signing key that is used to sign the claim with
return []byte("AllYourBase"), nil
}, jwt.WithLeeway(5*time.Second))
if err != nil {
Expand All @@ -167,6 +170,7 @@ func ExampleParse_errorChecking() {
var tokenString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.HE7fK0xOQwFEr4WDgRWj4teRPZ6i3GLwD5YCm6Pwu_c"

token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
// []byte("AllYourBase") refers to the signing key that is used to sign the claim with
return []byte("AllYourBase"), nil
})

Expand Down