package jwt import ( "strings" "zestack.dev/slim" ) type Finder func(c slim.Context) string func DefaultFinder(c slim.Context) string { if s := FromQuery(c); s != "" { return s } if s := FromHeader(c); s != "" { return s } return FromCookie(c) } func FromCookie(c slim.Context, keys ...string) string { for _, key := range keys { cookie, err := c.Cookie(key) if err == nil { return cookie.Value } } cookie, err := c.Cookie("jwt") if err != nil { return "" } return cookie.Value } func FromHeader(c slim.Context) string { bearer := c.Header("Authorization") if len(bearer) > 7 && strings.ToUpper(bearer[0:6]) == "BEARER" { return bearer[7:] } return "" } func FromQuery(c slim.Context, keys ...string) string { for _, key := range keys { s := c.QueryParam(key) if s != "" { return s } } return c.QueryParam("jwt") }