Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var JWTContext bearerware.JWTContexter
JWTContext stores the request scoped tokens
Functions ¶
func JWTHandler ¶
func JWTHandler( h httprouter.Handle, keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod, ) httprouter.Handle
JWTHandler is a JWT middleware for httprouter
Example ¶
var ( handler = func( w http.ResponseWriter, req *http.Request, _ httprouter.Params, ) { token, ok := bwhttprouter.JWTContext.ReadJWT(req) if !ok { http.Error( w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError, ) } fmt.Fprintf(w, "Token signed using %s", token.Method) } jwtKeyFunc = func(token *jwt.Token) (interface{}, error) { return []byte("MySecret"), nil } router = httprouter.New() ) router.GET( "/", bwhttprouter.JWTHandler(handler, jwtKeyFunc, jwt.SigningMethodHS256), ) if err := http.ListenAndServe("localhost:8080", router); err != nil { log.Print(err) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.