Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ func (config Config) ToMiddleware() (echo.MiddlewareFunc, error) {
return tmpErr
}

message := "invalid or expired jwt"
if lastTokenErr == nil {
message = "missing or malformed jwt"
return echo.NewHTTPError(http.StatusBadRequest, "missing or malformed jwt").SetInternal(err)
}
return echo.NewHTTPError(http.StatusUnauthorized, message).SetInternal(err)

return echo.NewHTTPError(http.StatusUnauthorized, "invalid or expired jwt").SetInternal(err)
}
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ func TestJWT_combinations(t *testing.T) {
config: Config{
SigningKey: validKey,
},
expectError: "code=401, message=missing or malformed jwt, internal=invalid value in request header",
expectError: "code=400, message=missing or malformed jwt, internal=invalid value in request header",
},
{
name: "Empty header auth field",
config: Config{
SigningKey: validKey,
},
expectError: "code=401, message=missing or malformed jwt, internal=invalid value in request header",
expectError: "code=400, message=missing or malformed jwt, internal=invalid value in request header",
},
{
name: "Valid query method",
Expand All @@ -180,7 +180,7 @@ func TestJWT_combinations(t *testing.T) {
TokenLookup: "query:jwt",
},
reqURL: "/?a=b&jwtxyz=" + token,
expectError: "code=401, message=missing or malformed jwt, internal=missing value in the query string",
expectError: "code=400, message=missing or malformed jwt, internal=missing value in the query string",
},
{
name: "Invalid query param value",
Expand All @@ -198,7 +198,7 @@ func TestJWT_combinations(t *testing.T) {
TokenLookup: "query:jwt",
},
reqURL: "/?a=b",
expectError: "code=401, message=missing or malformed jwt, internal=missing value in the query string",
expectError: "code=400, message=missing or malformed jwt, internal=missing value in the query string",
},
{
config: Config{
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestJWT_combinations(t *testing.T) {
SigningKey: validKey,
TokenLookup: "cookie:jwt",
},
expectError: "code=401, message=missing or malformed jwt, internal=missing value in cookies",
expectError: "code=400, message=missing or malformed jwt, internal=missing value in cookies",
},
{
name: "Valid form method",
Expand All @@ -264,7 +264,7 @@ func TestJWT_combinations(t *testing.T) {
SigningKey: validKey,
TokenLookup: "form:jwt",
},
expectError: "code=401, message=missing or malformed jwt, internal=missing value in the form",
expectError: "code=400, message=missing or malformed jwt, internal=missing value in the form",
},
}

Expand Down