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 http.HandlerFunc, keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod, ) http.HandlerFunc
JWTHandler is JWT middleware for net/http
Example ¶
var ( handler = func(w http.ResponseWriter, req *http.Request) { token, ok := bwhttp.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 } mux = http.NewServeMux() ) mux.HandleFunc( "/", bwhttp.JWTHandler(handler, jwtKeyFunc, jwt.SigningMethodHS256), ) if err := http.ListenAndServe("localhost:8080", mux); err != nil { log.Print(err) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.