File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 5252 // Possible values:
5353 // - "header:<name>"
5454 // - "query:<name>"
55+ // - "param:<name>"
5556 // - "cookie:<name>"
5657 TokenLookup string
5758
@@ -155,6 +156,8 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc {
155156 switch parts [0 ] {
156157 case "query" :
157158 extractor = jwtFromQuery (parts [1 ])
159+ case "param" :
160+ extractor = jwtFromParam (parts [1 ])
158161 case "cookie" :
159162 extractor = jwtFromCookie (parts [1 ])
160163 }
@@ -228,6 +231,17 @@ func jwtFromQuery(param string) jwtExtractor {
228231 }
229232}
230233
234+ // jwtFromParam returns a `jwtExtractor` that extracts token from the url param string.
235+ func jwtFromParam (param string ) jwtExtractor {
236+ return func (c echo.Context ) (string , error ) {
237+ token := c .Param (param )
238+ if token == "" {
239+ return "" , ErrJWTMissing
240+ }
241+ return token , nil
242+ }
243+ }
244+
231245// jwtFromCookie returns a `jwtExtractor` that extracts token from the named cookie.
232246func jwtFromCookie (name string ) jwtExtractor {
233247 return func (c echo.Context ) (string , error ) {
Original file line number Diff line number Diff line change @@ -159,6 +159,14 @@ func TestJWT(t *testing.T) {
159159 expErrCode : http .StatusBadRequest ,
160160 info : "Empty query" ,
161161 },
162+ {
163+ config : JWTConfig {
164+ SigningKey : validKey ,
165+ TokenLookup : "param:jwt" ,
166+ },
167+ reqURL : "/" + token ,
168+ info : "Valid param method" ,
169+ },
162170 {
163171 config : JWTConfig {
164172 SigningKey : validKey ,
@@ -195,6 +203,11 @@ func TestJWT(t *testing.T) {
195203 req .Header .Set (echo .HeaderCookie , tc .hdrCookie )
196204 c := e .NewContext (req , res )
197205
206+ if tc .reqURL == "/" + token {
207+ c .SetParamNames ("jwt" )
208+ c .SetParamValues (token )
209+ }
210+
198211 if tc .expPanic {
199212 assert .Panics (t , func () {
200213 JWTWithConfig (tc .config )
You can’t perform that action at this time.
0 commit comments