1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-15 23:41:29 +02:00

Add HandleEmptyToken to JWT middleware

Now it is possible to add custom handler for missing JWT.
This commit is contained in:
Przemek Komosa
2016-07-02 00:55:11 +02:00
parent bb6baa2088
commit ae09482493
2 changed files with 46 additions and 4 deletions

View File

@@ -19,6 +19,9 @@ func TestJWT(t *testing.T) {
validKey := []byte("secret")
invalidKey := []byte("invalid-key")
validAuth := bearer + " " + token
redirect := func(c echo.Context) error {
return echo.NewHTTPError(http.StatusFound, "redirect")
}
for _, tc := range []struct {
expPanic bool
@@ -60,6 +63,15 @@ func TestJWT(t *testing.T) {
expErrCode: http.StatusBadRequest,
info: "Empty header auth field",
},
{
config: JWTConfig{
SigningKey: validKey,
HandleEmptyToken: redirect,
},
hdrAuth: "",
expErrCode: http.StatusFound,
info: "Empty header auth field with redirect",
},
{
config: JWTConfig{
SigningKey: validKey,
@@ -95,6 +107,16 @@ func TestJWT(t *testing.T) {
expErrCode: http.StatusBadRequest,
info: "Empty query",
},
{
config: JWTConfig{
SigningKey: validKey,
TokenLookup: "query:jwt",
HandleEmptyToken: redirect,
},
reqURL: "/?a=b",
expErrCode: http.StatusFound,
info: "Empty query with redirect",
},
} {
if tc.reqURL == "" {