AuthFromQueryParam is a middleware that extracts the token from the query parameter and verifies it
(keyFunc jwt.Keyfunc, claimsFunc ClaimsFunc, signingMethod jwt.SigningMethod, next nhttp.Handler)
| 37 | |
| 38 | // AuthFromQueryParam is a middleware that extracts the token from the query parameter and verifies it |
| 39 | func AuthFromQueryParam(keyFunc jwt.Keyfunc, claimsFunc ClaimsFunc, signingMethod jwt.SigningMethod, next nhttp.Handler) nhttp.Handler { |
| 40 | return nhttp.HandlerFunc(func(w http.ResponseWriter, r *nhttp.Request) { |
| 41 | token := r.URL.Query().Get("t") |
| 42 | if token == "" { |
| 43 | nhttp.Error(w, "missing token", nhttp.StatusUnauthorized) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | verifyJWTAndServeNext(w, r, token, keyFunc, claimsFunc, signingMethod, next) |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | // verifyJWTAndServeNext verifies the token and serves the next handler |
| 52 | func verifyJWTAndServeNext(w http.ResponseWriter, r *nhttp.Request, token string, keyFunc jwt.Keyfunc, claimsFunc ClaimsFunc, signingMethod jwt.SigningMethod, next nhttp.Handler) { |